Reputation: 21
The documentation for ndims states that
N = ndims(A) returns the number of dimensions in the array A. The number of dimensions is always greater than or equal to 2
Doesn't a single dimension array, i.e., a row vector mean a dimension of 1?
Upvotes: 1
Views: 165
Reputation: 24169
If you look inside ndims.m
, you can see
Put simply, it is LENGTH(SIZE(X)).
Now size
always returns a vector of length >=2, even for empty arrays (i.e. size([])
is [0 0]
). Why that is? Likely a design choice made by TMW long ago.
If you want to measure "actual dimensions" you might want to use:
function nad = nActDims(in)
if numel(in) == 1
nad = 1;
else
nad = sum(size(in)>1);
end
or some combination of the functions isscalar
, isvector
, ismatrix
.
Upvotes: 1