I have Matlab code that is generating an array of variable size depending on some input parameter, N. Dimensions 1 and 2 are fixed, and the array's size in the 3rd dimension is N, i.e. size(A) = [x, y, N]. N can take integer values from 1 upwards.
Thus in the case N=1, I am indexing into the array as follows:
B = A(:, :, 1)
Here A reduces to a 2D matrix, but Matlab can handle indexing at 1 into higher dimensions.
Once this code is compiled using the Matlab Compiler SDK, running the executable causes an error, as it seems the runtime cannot handle indexing at 1 into dimension 3. Printing size(A) gives [x, y, 0] and thus a badsubscript error.
I guess I could add logic to handle indexing into A in the case that N=1, but that seems like a cludge as N=1 isn't exactly a special case in any other context. But I was hoping there was a better way to do this?