Main Content

isStringScalar

Determine if input is string array with one element

Description

example

tf = isStringScalar(A) returns 1 (true) if A is a string array and A has only one element. Otherwise, it returns 0 (false).

Examples

collapse all

Create different arrays, and then determine if they are string scalars.

Test a string scalar.

str = "Mercury"
str = 
"Mercury"
tf = isStringScalar(str)
tf = logical
   1

Test a string array with multiple elements. Since str contains more than one element, isStringScalar returns 0.

str = ["Mercury","Gemini","Apollo"]
str = 1x3 string
    "Mercury"    "Gemini"    "Apollo"

tf = isStringScalar(str)
tf = logical
   0

Test a character vector. Since character vectors are not strings, isStringScalar returns 0.

chr = 'Pluto'
chr = 
'Pluto'
tf = isStringScalar(chr)
tf = logical
   0

Input Arguments

collapse all

Input array, specified as an array of any size and data type.

Version History

Introduced in R2017b