Documentation |
Compare strings (case insensitive)
TF = strcmpi(string,string)
TF = strcmpi(string,cellstr)
TF = strcmpi(cellstr,cellstr)
TF = strcmpi(string,string) compares two strings for equality, ignoring any differences in letter case. The strings 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(string,cellstr) compares a string with each element of a cell array of strings, ignoring letter case. The function returns a logical array the same size as the cellstr input in which logical 1 represents equality. The order of the input arguments is not important.
TF = strcmpi(cellstr,cellstr) compares each element of one cell array of strings with the same element of the other, ignoring letter case. The function returns a logical array the same size as the input arrays.
string |
A single character string or n-by-1 array of strings. |
cellstr |
A cell array of strings. |
Perform a simple case-insensitive comparison of two strings:
strcmpi('Yes', 'No') ans = 0 strcmpi('Yes', 'yes') ans = 1
Create two cell arrays of strings and call strcmpi to compare them:
A = {'Handle Graphics', 'Statistics'; ... ' Toolboxes', 'MathWorks'}; B = {'Handle 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 "Handle 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.