What are the meanings of ndims (A), length (A), and size (A) in MATLAB?

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.