MATLAB Functions | Help Desk |
size
Array dimensions
d = size(X)
[m,n] = size(X)
m = size(X,
dim)
[d1,d2,d3,...,dn] = size(X)
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:
rand(2,3,4)
is 3.
m = size(rand(2,3,4),2) m = 3Here the size is output as a single vector.
d = size(rand(2,3,4)) d = 2 3 4Here the size of each dimension is assigned to a separate variable.
[m,n,p] = size(rand(2,3,4)) m = 2 n = 3 p = 4If X = ones(3,4,5), then
[d1,d2,d3] = size(X) d1 = d2 = d3 = 3 4 5but when the number of output variables is less than ndims(X):
[d1,d2] = size(X) d1 = d2 = 3 20The "extra" dimensions are collapsed into a single product. If n > ndims(X), the "extra" variables all represent singleton dimensions:
[d1,d2,d3,d4,d5,d6] = size(X) d1 = d2 = d3 = 3 4 5 d4 = d5 = d6 = 1 1 1
exist
Check if a variable or file exists
length
Length of vector
whos
List directory of variables in memory