Programming Previous page   Next Page

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.

Function
Description
length
Return the length of the longest dimension. (The length of a matrix or array with any zero dimension is zero.)
ndims
Return the number of dimensions.
numel
Return the number of elements.
size
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

Using the numel function, find the average of all values in matrix A:

Example Using ndims, numel, and size

Using ndims and size, go through the matrix and find those values that are between 5 and 7, inclusive:

The code returns the following:


Previous page  Logical Indexing Data Types Used in the Matrix Next page

© 1994-2005 The MathWorks, Inc.