This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Matrices and Arrays

Array creation, combining, reshaping, rearranging, and indexing

Matrices and arrays are the fundamental representation of information and data in MATLAB®. You can create common arrays and grids, combine existing arrays, manipulate an array's shape and content, and use indexing to access array elements. For an overview of matrix and array manipulation, watch Working with Arrays.


zeros Create array of all zeros
ones Create array of all ones
rand Uniformly distributed random numbers
true Logical 1 (true)
false Logical 0 (false)
eye Identity matrix
diag Create diagonal matrix or get diagonal elements of matrix
blkdiag Construct block diagonal matrix from input arguments
cat Concatenate arrays along specified dimension
horzcat Concatenate arrays horizontally
vertcat Concatenate arrays vertically
repelem Repeat copies of array elements
repmat Repeat copies of array
linspace Generate linearly spaced vector
logspace Generate logarithmically spaced vector
freqspace Frequency spacing for frequency response
meshgrid 2-D and 3-D grids
ndgrid Rectangular grid in N-D space
length Length of largest array dimension
size Array size
ndims Number of array dimensions
numel Number of array elements
isscalar Determine whether input is scalar
isvector Determine whether input is vector
ismatrix Determine whether input is matrix
isrow Determine whether input is row vector
iscolumn Determine whether input is column vector
isempty Determine whether array is empty
sort Sort array elements
sortrows Sort rows of matrix or table
issorted Determine if array is sorted
issortedrows Determine if matrix or table rows are sorted
flip Flip order of elements
fliplr Flip array left to right
flipud Flip array up to down
rot90 Rotate array 90 degrees
transpose Transpose vector or matrix
ctranspose Complex conjugate transpose
permute Rearrange dimensions of N-D array
ipermute Inverse permute dimensions of N-D array
circshift Shift array circularly
shiftdim Shift dimensions
reshape Reshape array
squeeze Remove singleton dimensions
colon Vector creation, array subscripting, and for-loop iteration
end Terminate block of code, or indicate last array index
ind2sub Subscripts from linear index
sub2ind Convert subscripts to linear indices


Creating and Concatenating Matrices

Create a matrix or construct one from other matrices.

Matrix Indexing

Access or assign to elements of a matrix using methods of row and column indexing.

Resizing and Reshaping Matrices

Change the size, shape, or arrangement of elements in an existing matrix.

Shifting and Sorting Matrices

Shift matrix elements along one or more dimensions, or sort them into ascending or descending order.

Operating on Diagonal Matrices

Construct and manipulate matrices along a diagonal.

Empty Matrices, Scalars, and Vectors

Work with matrices that have one or more dimensions equal to zero or one.

Multidimensional Arrays

Create and work with arrays that have more than two dimensions.

Was this topic helpful?