Compare strings (case insensitive)
TF = strcmpi(str,str)
TF = strcmpi(str,C)
TF = strcmpi(C,C)
compares
two character vectors for equality, ignoring any differences in letter
case. The character vectors are considered to be equal if the size
and content of each are the same. The function returns a scalar logical
1 for equality, or scalar logical 0 for inequality.TF
= strcmpi(str
,str
)
compares
a character vector with each element of a cell array of character
vectors, ignoring letter case. The function returns a logical array
the same size as the TF
= strcmpi(str
,C
)C
input in which logical 1
represents equality. The order of the input arguments is not important.
compares
each element of one cell array of character vectors with the same
element of the other, ignoring letter case. The function returns a
logical array the same size as the input arrays.TF
= strcmpi(C
,C
)
|
A character vector or m-by-n character array. |
|
A cell array of character vectors. |
|
When both inputs are character arrays, When either or both inputs are a cell array of character vectors, |
Perform a simple case-insensitive comparison of two character vectors:
strcmpi('Yes', 'No') ans = 0 strcmpi('Yes', 'yes') ans = 1
Create two cell arrays of character vectors and call strcmpi
to
compare them:
A = {'Graphics', 'Statistics'; ... ' Toolboxes', 'MathWorks'}; B = {'Graphics', 'Signal Processing'; ... 'Toolboxes', 'MATHWORKS'};
match = strcmpi(A, B) match = 1 0 0 1
The result of comparing the two cell arrays is:
match{1,1}
is 1 because "Graphics"
in A{1,1}
matches the same text in B{1,1}
.
match{1,2}
is 0 because "Statistics"
in A{1,2}
does not match "Signal Processing"
in B{1,2}
.
match{2,1}
is 0 because " Toolboxes", in A{2,1}
contains
leading space characters that are not in B{2,1}
.
match{2,2}
is 1 because even though
"MathWorks" in A{2,2}
uses different
letter case than "MATHWORKS" in B{2,2}
, strcmpi
performs
the comparison without sensitivity to letter case.