This is machine translation

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


Compare strings (case insensitive)


TF = strcmpi(str,str)
TF = strcmpi(str,C)
TF = strcmpi(C,C)


TF = strcmpi(str,str) 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,C) 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 C input in which logical 1 represents equality. The order of the input arguments is not important.

TF = strcmpi(C,C) 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.

Input Arguments


A character vector or m-by-n character array.


A cell array of character vectors.

Output Arguments


When both inputs are character arrays, TF is a scalar logical value. This value is logical 1 (true) if the size and content of both arrays are equal, and logical 0 (false) if they are not.

When either or both inputs are a cell array of character vectors, TF is an array of logical ones and zeros. This array is the same size as the input cell array(s), and contains logical 1 (true) for those elements of the input arrays that are a match, and logical 0 (false) for those elements that are not.


Perform a simple case-insensitive comparison of two character vectors:

strcmpi('Yes', 'No')
ans =
strcmpi('Yes', 'yes')
ans =

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.

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.


  • The strcmpi function is intended for comparison of character data. When used to compare numeric data, it returns logical 0.

  • Use strcmp for case-sensitive text comparisons.

  • Any leading and trailing blanks in either of the character vectors are explicitly included in the comparison.

  • The value returned by strcmpi is not the same as the C language convention.

  • strcmpi supports international character sets.

Introduced before R2006a

Was this topic helpful?