This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Determine if input is character array


tf = ischar(A)



tf = ischar(A) returns logical 1 (true) if A is a character array and logical 0 (false) otherwise.


collapse all

Create different arrays, and then determine if they are character arrays.

Test a character vector.

chr = 'Mary Jones'
chr = 
'Mary Jones'
tf = ischar(chr)
tf = logical

Test a numeric array.

X = rand(1,3)
X = 

    0.8147    0.9058    0.1270

tf = ischar(X)
tf = logical

Test a string array. Starting in R2017a, you can create strings using double quotes instead of the string function.

str = ["Smith","Chung","Morales"; ...
str = 2×3 string array
    "Smith"      "Chung"       "Morales"
    "Sanchez"    "Peterson"    "Adams"  

tf = ischar(str)
tf = logical

str is a string array, not a character array, so ischar returns 0.

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. A can be any data type.

Extended Capabilities

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

Introduced before R2006a

Was this topic helpful?