# 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 `combinations` Generate all element combinations of arrays
 `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 if input is row vector `iscolumn` Determine if input is column vector `isempty` Determine whether array is empty `issorted` Determine if array is sorted `issortedrows` Determine if matrix or table rows are sorted `isuniform` Determine if vector is uniformly spaced
 `sort` Sort array elements `sortrows` Sort rows of matrix or table `head` Get top rows of array or table `tail` Get bottom rows of array 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` Convert linear indices to subscripts `sub2ind` Convert subscripts to linear indices