# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# size

## Syntax

sz = size(A)
szdim = size(A,dim)
[m,n] = size(A)
[sz1,...,szN] = size(A)

## Description

example

sz = size(A) returns a row vector whose elements contain the length of the corresponding dimension of A. For example, if A is a 3-by-4 matrix, then size(A) returns the vector [3 4]. The length of sz is ndims(A).

If A is a table or timetable, then size(A) returns a two-element row vector consisting of the number of rows and the number of table variables.

example

szdim = size(A,dim) returns the length of dimension dim.

example

[m,n] = size(A) returns the number of rows and columns when A is a matrix.

example

[sz1,...,szN] = size(A) returns the length of each dimension of A separately.

## Examples

collapse all

Create a random matrix and compute the number of rows and columns.

A = rand(4,3);
[m,n] = size(A)
m = 4
n = 3

Create a random 3-D array and find its size.

A = rand(2,3,4);
sz = size(A)
sz =

2     3     4

Find only the length of the second dimension of A.

szdim2 = size(A,2)
szdim2 = 3

Assign the length of each dimension to a separate variable.

[sz1,sz2,sz3] = size(A)
sz1 = 2
sz2 = 3
sz3 = 4

Create a table with 5 rows and 4 variables.

LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];

A = table(Age,Height,Weight,BloodPressure,'RowNames',LastName)
A=5x4 table null
Age    Height    Weight    BloodPressure
___    ______    ______    _____________

Smith       38     71        176       124     93
Johnson     43     69        163       109     77
Williams    38     64        131       125     83
Jones       40     67        133       117     75
Brown       49     64        119       122     80

Find the size of the table. Although the BloodPressure variable contains two columns, size only counts the number of variables.

sz = size(A)
sz =

5     4

Create a 3-D array and assign the length of each dimension to a separate variable. Each output argument corresponds to one dimension of A.

A = ones(3,4,5);
[sz1,sz2,sz3] = size(A)
sz1 = 3
sz2 = 4
sz3 = 5

Specify only two output arguments when computing the size of A. Since a third output argument is not specified, the lengths of the second and third dimensions of A are collapsed into sz2.

[sz1,sz2] = size(A)
sz1 = 3
sz2 = 20

Specify more than three output variables when computing the size of A. The fourth and fifth output arguments are set to 1.

[sz1,sz2,sz3,sz4,sz5] = size(A)
sz1 = 3
sz2 = 4
sz3 = 5
sz4 = 1
sz5 = 1

## Input Arguments

collapse all

Input array, specified as a scalar, a vector, a matrix, or a multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | function_handle | cell | categorical | datetime | duration | calendarDuration | table | timetable

Complex Number Support: Yes

Queried dimension, specified as a positive integer scalar. size returns the length of dimension dim of A.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

## Output Arguments

collapse all

Array size, returned as a row vector of nonnegative integers. Each element of the vector represents the length of the corresponding dimension of A. If A is a scalar, then sz is the row vector [1 1]. If A is a table or timetable, then sz is a two-element row vector containing the number of rows and the number of variables. Multiple columns within a single variable are not counted.

Data Types: double

Length of specified dimension, returned as a nonnegative integer scalar.

Data Types: double

Number of rows, returned as a nonnegative integer scalar when A is a matrix.

Data Types: double

Number of columns, returned as a nonnegative integer scalar when A is a matrix.

Data Types: double

Dimension lengths, returned as nonnegative integer scalars. When the specified number of output arguments is equal to ndims(A), then each argument is the length of the corresponding dimension of A. If more than ndims(A) output arguments are specified, then the extra output arguments are set to 1. For example, for a matrix A with size [4 5], [sz1,sz2,sz3] = size(A) returns sz1 = 4, sz2 = 5, and sz3 = 1.

If fewer than ndims(A) output arguments are specified, then all remaining dimension lengths are collapsed into the last argument in the list. For example, if A is a 3-D array with size [3 4 5], then [sz1,sz2] = size(A) returns sz1 = 3 and sz2 = 20.

Data Types: double

## Tips

• To determine if an array is empty, a scalar, or a matrix, use the functions isempty, isscalar, and ismatrix. You can also determine the orientation of a vector with the isrow and iscolumn functions.