MATLAB Function Reference
  Go to function:
    Search    Help Desk 
size    Examples   See Also

Array dimensions

Syntax

Description

d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements.

[m,n] = size(X) returns the size of matrix X in variables m and n.

m = size(X,dim) returns the size of the dimension of X specified by scalar dim.

[d1,d2,d3,...,dn] = size(X) returns the sizes of the various dimensions of array X in separate variables.

If the number of output arguments n does not equal ndims(X), then:

If n > ndims(X)
Ones are returned in the "extra" variables dndims(X)+1 through dn.
If n < ndims(X)
The final variable dn contains the product of the sizes of all the "remaining" dimensions of X, that is, dimensions n+1 through ndims(X).

Examples

The size of the second dimension of rand(2,3,4) is 3.

Here the size is output as a single vector.

Here the size of each dimension is assigned to a separate variable.

If X = ones(3,4,5), then

but when the number of output variables is less than ndims(X):

The "extra" dimensions are collapsed into a single product.

If n > ndims(X), the "extra" variables all represent singleton dimensions:

See Also

exist       Check if a variable or file exists

length      Length of vector

whos        List directory of variables in memory



[ Previous | Help Desk | Next ]