isscalar

Tests whether the input has exactly one element.

Category: Language Fundamentals > Matrices and Arrays

Syntax

tf = isscalar(A)

True when A is 1-by-1.

Description

The test is on the size, not the class: a one-element cell {1} and a string scalar "abc" are scalars, while a character vector 'abc' is not because it has three elements. An empty array is not a scalar.

Input arguments

A
Any array, including cell arrays, structs and text.

Output arguments

tf
Logical scalar.

Example

isscalar(5)
isscalar([1 2])
isscalar({1})
isscalar("abc")
isscalar('abc')
Output
ans = logical
   1
ans = logical
   0
ans = logical
   1
ans = logical
   1
ans = logical
   0

See also

isvector isrow iscolumn isempty