strcmp in matlab

In MATLAB, we can use the strcmp() function to compare two strings. The function returns logical 1 (true) if the strings are equal, and 0 (false) otherwise. Here's an example:

main.m
str1 = 'hello';
str2 = 'world';
if strcmp(str1, str2)
    disp('strings are equal');
else
    disp('strings are not equal');
end
129 chars
8 lines

In the above example, since str1 and str2 are not equal, strcmp() returns 0, and the output will be "strings are not equal".

related categories

gistlibby LogSnag