Main Content

isscalar

Determine whether input is scalar

Description

example

TF = isscalar(A) returns logical 1 (true) if A is a scalar. Otherwise, it returns logical 0 (false). A scalar is a two-dimensional array that has a size of 1-by-1.

Examples

collapse all

Create a 2-by-2 matrix. Determine whether it is a scalar.

A = [1 2; 3 4];
TF = isscalar(A)
TF = logical
   0

Check whether the element at the first row and second column of the matrix is a scalar.

TF = isscalar(A(1,2))
TF = logical
   1

Create a string scalar by enclosing a piece of text in double quotes. Determine whether it is a scalar.

A = "Hello, World!";
TF = isscalar(A)
TF = logical
   1

Now create a character vector by enclosing a piece of text in single quotes. Determine whether it is a scalar.

B = 'Hello, World!';
TF = isscalar(B)
TF = logical
   0

Check the dimension of B using size. B is not a scalar since it has a size of 1-by-13.

sz = size(B)
sz = 1×2

     1    13

Input Arguments

collapse all

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a