Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the 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.

## Functions

expand all

 `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` Block diagonal matrix `cat` Concatenate arrays `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 `issorted` Determine if array is sorted `issortedrows` Determine if matrix or table rows are sorted `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 `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` Permute array dimensions `ipermute` Inverse permute array dimensions `circshift` Shift array circularly `shiftdim` Shift array dimensions `reshape` Reshape array `squeeze` Remove dimensions of length 1
 `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

## Topics

Creating, Concatenating, and Expanding Matrices

Create a matrix or construct one from other matrices.

Array Indexing

Access elements of an array.

Removing Rows or Columns from a Matrix

Remove matrix rows or columns.

Reshaping and Rearranging Arrays

Change the shape or arrangement of elements in an existing array.

Multidimensional Arrays

Create and manipulate arrays with three or more dimensions.