How to check array dimensions

There are a few matlab commands to determine array size or shape:

length:  finds the number of elements along the largest dimension of an array.
ndims:  returns the number of dimensions of the array.
size:      returns the sizes of each dimension in the array.
numel:  returns the number of elements in the array.
isrow:   determine whether input is row vector (true=1 or false=0).
iscolumn: determine whether input is column vector (true=1 or false=0).
isscalar:   determine whether input is scalar (true=1 or false=0).
isvector:  determine whether input is vector (true=1 or false=0).
ismatrix:  determine whether input is a matrix (true=1 or false=0).

Next table shows some examples:

Array length ndims size numel
 2 1 2 1  2 1
[1 2 3 4] 4 2 1  4 4
[1 2; 3 4] 2 2 2  2 4
 ones(3,6) 6 2 3  6 18
zeros(2,3,100) 100 3 2  3  100 600

 

Array iscolumn isrow isscalar isvector
 2 1 1 1 1
[1 2 3 4] 0 1 0 1
[1 2; 3 4] 0 0 0 0
 ones(3,6) 0 0 0 0
zeros(2,3,100) 0 0 0 0

 

Advertisements
This entry was posted in arrays and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s