Compare two nonscalar string arrays. When you compare two nonscalar arrays, they must
be the same size.
str2 = ["Mercury","Mars","Apollo";...
"Jupiter","Saturn","Neptune"];
TF = (str1 == str2)
TF = 2x3 logical array
1 0 1
0 0 0
Index into str1 to extract the matches.
str1(TF)
ans = 2x1 string array
"Mercury"
"Apollo"
Compare String Arrays with Other Relational Operators
You can also compare strings with the relational operators >, >=, <, and <=. Strings that
start with uppercase letters come before strings that start with lowercase letters. For
example, the string "ABC" is less than "abc". Digits and some punctuation marks also
come before letters.
"ABC" < "abc"
ans = logical
1
Compare a string array that contains names to another name with the > operator. The
names Sanchez, de Ponte, and Nash come after Matthews, because S, d, and N all are
greater than M.
str = ["Sanchez","Jones","de Ponte","Crosby","Nash"];
TF = (str > "Matthews")
TF = 1x5 logical array
1 0 1 0 1
Compare Text