Programming Previous page   Next Page

Summary of Matrix and Array Functions

This section summarizes the principal functions used in creating and handling matrices. Most of these functions work on multidimensional arrays as well.

Functions to Create a Matrix

Function
Description
[a,b] or [a;b]
Create a matrix from specified elements, or concatenate matrices together.
accumarray
Construct a matrix using accumulation.
blkdiag
Construct a block diagonal matrix.
cat
Concatenate matrices along the specified dimension.
diag
Create a diagonal matrix from a vector.
horzcat
Concatenate matrices horizontally.
magic
Create a square matrix with rows, columns, and diagonals that add up to the same number.
ones
Create a matrix of all ones.
rand
Create a matrix of uniformly distributed random numbers.
repmat
Create a new matrix by replicating or tiling another.
vertcat
Concatenate two or more matrices vertically.
zeros
Create a matrix of all zeros.


Functions to Modify the Shape of a Matrix

Function
Description
ctranspose
Flip a matrix about the main diagonal and replace each element with its complex conjugate.
flipdim
Flip a matrix along the specified dimension.
fliplr
Flip a matrix about a vertical axis.
flipud
Flip a matrix about a horizontal axis.
reshape
Change the dimensions of a matrix.
rot90
Rotate a matrix by 90 degrees.
transpose
Flip a matrix about the main diagonal.


Functions to Find the Structure or Shape of a Matrix

Function
Description
isempty
Return true for 0-by-0 or 0-by-n matrices.
isscalar
Return true for 1-by-1 matrices.
issparse
Return true for sparse matrices.
isvector
Return true for 1-by-n matrices.
length
Return the length of a vector.
ndims
Return the number of dimensions in a matrix.
numel
Return the number of elements in a matrix.
size
Return the size of each dimension.


Functions to Determine Data Type

Function
Description
iscell
Return true if the matrix is a cell array.
ischar
Return true if matrix elements are characters or strings.
isfloat
Determine if input is a floating point array.
isinteger
Determine if input is an integer array.
islogical
Return true if matrix elements are logicals.
isnumeric
Return true if matrix elements are numeric.
isreal
Return true if matrix elements are real numbers.
isstruct
Return true if matrix elements are MATLAB structures.


Functions to Sort and Shift Matrix Elements

Function
Description
circshift
Circularly shift matrix contents.
issorted
Return true if the matrix elements are sorted.
sort
Sort elements in ascending or descending order.
sortrows
Sort rows in ascending order.


Functions That Work on Diagonals of a Matrix

Function
Description
blkdiag
Construct a block diagonal matrix.
diag
Return the diagonals of a matrix.
trace
Compute the sum of the elements on the main diagonal.
tril
Return the lower triangular part of a matrix.
triu
Return the upper triangular part of a matrix.


Functions to Change the Indexing Style

Function
Description
ind2sub
Convert a linear index to a row-column index.
sub2ind
Convert a row-column index to a linear index.


Functions for Working with Multidimensional Arrays

Function
Description
cat
Concatenate arrays.
circshift
Shift array circularly.
ipermute
Inverse permute array dimensions.
ndgrid
Generate arrays for n-dimensional functions and interpolation.
ndims
Return the number of array dimensions.
permute
Permute array dimensions.
shiftdim
Shift array dimensions.
squeeze
Remove singleton dimensions.


Previous page  Multidimensional Structure Arrays Data Types Next page

© 1994-2005 The MathWorks, Inc.