Navigation

Operators and Keywords

Function List:

C++ API

: sz = size (a)
: dim_sz = size (a, dim)
: [rows, cols, …, dim_N_sz] = size (…)

Return a row vector with the size (number of elements) of each dimension for the object a.

When given a second argument, dim, return the size of the corresponding dimension.

With a single output argument, size returns a row vector. When called with multiple output arguments, size returns the size of dimension N in the Nth argument. The number of rows, dimension 1, is returned in the first argument, the number of columns, dimension 2, is returned in the second argument, etc. If there are more dimensions in a then there are output arguments, size returns the total number of elements in the remaining dimensions in the final output argument.

Example 1: single row vector output

size ([1, 2; 3, 4; 5, 6])
  ⇒ [ 3, 2 ]

Example 2: number of elements in 2nd dimension (columns)

size ([1, 2; 3, 4; 5, 6], 2)
   ⇒ 2

Example 3: number of output arguments == number of dimensions

[nr, nc] = size ([1, 2; 3, 4; 5, 6])
   ⇒ nr = 3
   ⇒ nc = 2

Example 4: number of output arguments != number of dimensions

[nr, remainder] = size (ones (2, 3, 4, 5))
   ⇒ nr = 2
   ⇒ remainder = 60

See also: numel, ndims, length, rows, columns, size_equal, common_size.

Package: octave