MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Determine which characters in a character vector are space characters. isspace returns
a logical vector that is the same size as chr.

chr = 'Four score and seven years ago';
TF = isspace(chr)

TF = 1x30 logical array

0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0

The isstrprop function can query characters for many different traits. isstrprop can
determine whether characters in a string or character vector are letters, alphanumeric
characters, decimal or hexadecimal digits, or punctuation characters.

Determine which characters in a string are punctuation marks. isstrprop returns a
logical vector whose length is equal to the number of characters in str.

str = "A horse! A horse! My kingdom for a horse!"

str =
"A horse! A horse! My kingdom for a horse!"

isstrprop(str,"punct")

ans = 1x41 logical array

0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Determine which characters in the character vector chr are letters.

isstrprop(chr,"alpha")

ans = 1x30 logical array

1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1

See Also
eq | ge | gt | isletter | isspace | isstrprop | le | lt | ne | sort | strcmp

6 Characters and Strings

Free download pdf