Size (a) indicates the length of each dimension in the matrix.
For example, size ([1 2 3; 4 5 6])
Equal to [2 3]
It has two rows and three columns.
Size ([1 2 3])
Equal to [1 3]
It has one row and three columns.
In addition, size (A, n) indicates the length of matrix A in the nth dimension.
For example, size ([1 2 3; 4 5 6], 1)
Equal to 2, indicating 2 rows
Size ([1 2 3; 4 5 6], 2)
Equals to 3, indicating three columns
Length (a) indicates the maximum length of matrix A, that is, Max (SIZE ())
For example, length ([1 2 3; 4 5 6])
It is equal to 3 because the maximum value of 2 and 3 is 3.
When a is a vector, it indicates the number of elements in the vector. Because the vector is always 1 × n or n × 1, and N must be greater than or equal to 1, the result must be n.
Ndims (a) indicates the dimension of matrix A, that is, length (SIZE ())
For example, ndims ([1 2 3; 4 5 6])
Equal to 2 because it is a two-dimensional matrix.
MATLAB considers vector as a two-dimensional matrix, but the length of one dimension is 1.
Therefore, ndims ([1 2 3]) is equal to 2.
We can construct a matrix of three or more dimensions,
For example, a = CAT (3, [1 2 3 4; 5 6 7 8], [9 8 7 6; 5 4 3 2])
In addition to rows and columns, it also has a dimension, which we call height.
That is to say, a has two layers. The first layer is [1 2 3 4; 5 6 7 8], and the second layer is [9 8 7 6; 5 4 3 2].
Size (A) = [2 4 2]
2 rows, 4 columns, 2 layers
Length (A) = 4
(4 in [2 4 2)
Ndims (A) = 3
(Because it has three dimensions)
What are the meanings of ndims (A), length (A), and size (A) in MATLAB?