Skip to content

size

Sizes along all dimensions, or along one specific dimension.

sz = size(X)
n = size(X, dim)

With one argument, returns a row vector containing the size of X along each of its dimensions — first element is the row count, second is the column count, etc.

With two arguments, returns the size along the dimension dim only. dim is 1-based; passing a dim larger than ndims(X) raises an error.

size(zeros(3,5)) % [3 5]
size(zeros(3,5,2), 3) % 2
size([1 2 3 4]) % [1 4]
  • length — Length of the longest dimension.
  • numel — Total number of elements.
  • ndims — Number of dimensions of the input.
  • size_equal — Test whether all inputs share the same shape.