TF = matches(str,pat)
returns 1 (true) if the specified pattern matches
str, and returns 0 (false)
otherwise. If str is an array, then TF is an array of
the same size.
If pat is an array containing multiple patterns, then
matches returns 1 if it finds that any element of
pat matches str.
Find the strings that match "Earth". Return a logical array where the position of each element equal to 1 corresponds to the position of a matching string in str.
TF = matches(str,"Earth")
TF = 1×4 logical array
0 0 1 0
Display the match by indexing back into str using TF.
Create a pattern that matches the hexadecimal numbers. To match a single hexadecimal digit, specify a pattern that matches any digit, any capital letter A-F, or any lowercase letter a-f. Then, specify a pattern that begins with 0x and is followed by any number of hexadecimal digits.
pat = digitsPattern(1) | characterListPattern("A","F") | characterListPattern("a","f");
pat = "0x" + asManyOfPattern(pat)
Load data on electric utility outages in the United States as a table. Convert the Cause variable to a categorical array.
T = readtable("outages.csv");
T.Cause = categorical(T.Cause);
Determine if the category names of Cause match "earthquake". The matches function returns a logical array indicating which elements in the Cause categorical array have category names that match "earthquake".
The matches function now supports categorical arrays as the input
array. You can use this function to determine whether elements in a categorical array have
category names that match a specified pattern.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.