Getting Information About a Matrix
This section explains how to get the following information about an existing matrix:
Dimensions of the Matrix
These functions return information about the shape and size of a matrix.
||Return the length of the longest dimension. (The length of a matrix or array with any zero dimension is zero.)
||Return the number of dimensions.
||Return the number of elements.
||Return the length of each dimension.
The following examples show some simple ways to use these functions. Both use the 3-by-5 matrix
A shown here:
Example Using numel
numel function, find the average of all values in matrix
Example Using ndims, numel, and size
size, go through the matrix and find those values that are between 5 and 7, inclusive:
The code returns the following:
|Logical Indexing||Data Types Used in the Matrix|
© 1994-2005 The MathWorks, Inc.