0
0
0
Index into str1 with TF to extract the string elements that matched Gemini. You can use logical
arrays to index into an array.
str1(TF)
ans =
"Gemini"
Compare for inequality using the ~= operator. Index into str1 to extract the elements that do not
match 'Gemini'.
TF = (str1 ~= chr)
TF = 2x3 logical array
1
0
1
1
1
1
str1(TF)
ans = 5x1 string
"Mercury"
"Skylab"
"Skylab B"
"Apollo"
"International Space Station"
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
"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.
Compare Text
6-33
Précédent

- 215/1450

Suivant