size
Computes the dimensions of an expression.
Syntax
size(expr)
Argument
- expr
- A valid expression of any type.
Example
Templex Expression | Results |
---|---|
{size(4)} |
1, 1 |
{size( {1, 2, 3, 4} )} |
1, 4 |
{size( {1, 2, 3, 4}' )} |
4, 1 |
{size( { {1, 2}, {3, 4} } )} |
2, 2 |
{size("abc")} |
3 |
{size({"abc", "defg", "hi"})} |
3, 4, 2 |
Comments
If expr is a scalar, the result is a scalar with a value of one.
If expr is a row vector, the result is {1, x}
,
where x
is the number of elements of the row vector.
If expr is a column vector, the result is {x, 1}
,
where x
is the number of elements of the vector.
If expr is a matrix, the result is {m, n}
, where
m
and n
are the number of rows and columns,
respectively.
If expr is a string, the result is a scalar which is the number of characters in the string.
If expr is a string array, the result is a vector where each element is the number of characters in each corresponding element of the string array.