This is the expected behavior of multidimensional arrays.
Leading singleton dimensions are not dropped because they cannot be added on the fly (without a call to the RESHAPE function) to maintain memory integrity. However, trailing singleton dimensions are dropped because leaving them out will not affect memory integrity.
If the leading singleton dimensions are not required, the SQUEEZE function can be used. Hence for the example considered, the commands:
size(squeeze(myArr(:,1,:)))
size(squeeze(myArr(1,:,:)))
yield the results:
ans =
128 160
ans =
128 160
respectively, without displaying the singleton dimensions.
For more information regarding the SQUEEZE function, enter the following at the MATLAB Command Prompt:
Best Answer