Documentation Center

  • Trial Software
  • Product Updates


Number of array dimensions




N = ndims(A) returns the number of dimensions in the array A. The number of dimensions is always greater than or equal to 2. The function ignores trailing singleton dimensions, for which size(A,dim) = 1.


expand all

Find Dimensions of Vector

Create a row vector.

A = 1:5;

Find the number of dimensions in the vector.

ans =


The result is 2 because the vector has a size of 1-by-5.

Find Dimensions of Cell Array

Create a cell array of strings.

C{1,1,1} = 'cell_1';
C{1,1,2} = 'cell_2';
C{1,1,3} = 'cell_3'
C(:,:,1) = 


C(:,:,2) = 


C(:,:,3) = 


Find the number of dimensions of the cell array.

ans =


The result is 3 because the cell array has a size of 1-by-1-by-3.

Input Arguments

expand all

A — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. This includes numeric arrays, logical arrays, character arrays, categorical arrays, tables, structure arrays, cell arrays, and object arrays.

More About

expand all


The number of dimensions in an array is the same as the length of the size vector of the array. In other words, ndims(A) = length(size(A)).

See Also


Was this topic helpful?