I do not find this completely intuitive. In mathematics, there are vectors of 1 dimension (although they are isomorphic to scalars). In addition, the matrix may have a size of 1x1.
It is true that one number can be considered a scalar, 1-vector or 1x1-matrix. View Matlab:
- The scalar is considered a 1x1 matrix
- An n-vector is just 1 xn or nx 1 matrix
More generally: the long sizes of a singleton are not taken into account. For example, a 3D array of size 2x3x4 can also be considered, for example, a 5D array of size 2x3x4x1x1. This works without errors:
>> a = rand(2,3,4); >> a(2,2,2) ans = 0.2575 >> a(2,2,2,1,1) ans = 0.2575
Now, if you want to check if A vector, matrix, or multidimensional array with more than one element , use
numel(A)>1
The numel function returns the number of elements of the input argument.
source share