3.6. Multi-Dimensional Matrices and Arrays

Matrix dimensions are defined automatically. However, if it is desired to know the size of an existing matrix A, command, size(A), can be used. The format is as follows:

size(A)

The command returns the number of elements of the matrix in each dimension. These numbers returned by the size command can be assigned to variables and stored for use later in the program. For example, if the matrix is two-dimensional, the following command can be used:

[m, n] = size(A)

When executed, it will assign the number of rows of matrix A to variable ‘m’ and number of columns to variable ‘n’.

Referring to the matrix A in Section 3.5.1, the size can be obtained by the following command:

[m, n] = size(A)

This gives ...

Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.