The following keywords are here:
- The inconsistency you are talking about is deeply immersed in the Matlab language: all arrays are considered at least 2D . For example,
ndims(pi) gives 2 . - Another rule in Matlab is that it is assumed that all arrays have an infinite number of finite singleton sizes . For example,
size(pi,5) gives 1 .
According to observation 1, squeeze will not remove singleton sizes if it gives less than two dimensions. This is stated in the documentation:
B = squeeze(A) returns an array of B with the same elements as A , but when deleting all singleton sizes. A singleton size is any dimension for which size(A,dim) = 1 . Two-dimensional arrays are not affected by squeeze ; if A is a row or column vector or scalar (1-on-1) value, then B = A
If you want to get rid of the first singlet, you can use observation 2 and use reshape
numel_last_a = 1; numel_last_b = 2; a = rand(2,20,numel_last_a); b = rand(2,20,numel_last_b); as = reshape(sum(a,1), size(a,2), size(a,3)); bs = reshape(sum(b,1), size(b,2), size(b,3)); size(as) size(bs)
gives
ans = 20 1 ans = 20 2
source share