MATLAB Function Reference |
Syntax
Description
k = strcmp('str1', 'str2')
compares the strings str1
and str2
and returns logical 1 (true
) if the two are identical and logical 0 (false
) otherwise.
TF = strcmp(S, T)
where either S
or T
is a cell array of strings, returns an array TF
the same size as S
and T
containing logical 1
(true
) for those elements of S
and T
that match and logical 0
(false
) otherwise. S
and T
must be the same size (or one can be a scalar cell). Either one can also be a character array with the right number of rows.
Remarks
Note that the value returned by strcmp
is not the same as the C language convention. In addition, the strcmp
function is case sensitive; any leading and trailing blanks in either of the strings are explicitly included in the comparison.
strcmp
is intended for comparison of character data. When used to compare numeric data, strcmp
returns logical 0
.
Examples
strcmp('Yes', 'No') = 0 strcmp('Yes', 'Yes') = 1 A = 'MATLAB' 'SIMULINK' 'Toolboxes' 'The MathWorks' B = 'Handle Graphics' 'Real Time Workshop' 'Toolboxes' 'The MathWorks' C = 'Signal Processing' 'Image Processing' 'MATLAB' 'SIMULINK' strcmp(A, B) ans = 0 0 1 1 strcmp(A, C) ans = 0 0 0 0
See Also
strcmpi
, strncmp
, strncmpi
, strmatch
, strfind
, findstr
, regexp
, regexp
i, regexprep
strcat | strcmpi |
© 1994-2005 The MathWorks, Inc.