Count the number of occurrences of the sequence of characters, red, in string arrays.
Starting in R2017a, you can create a string using double quotes.
str = "paired with red shoes"
str =
"paired with red shoes"
To count the occurrences of red, use the count function. In this example, the result is 2 because red is also part of the word paired.
A = count(str,"red")
A = 2
Create a 2-by-1 string array.
str = ["red green red red blue blue green";
"green red blue green green blue"]
str = 2x1 string
"red green red red blue blue green"
"green red blue green green blue"
Count the occurrences of red in each element of str. If str is a string array or cell array of character vectors, then A is a numeric array that has the same size.
Count the total number of occurrences of red and blue in a string array.
Starting in R2017a, you can create strings using double quotes.
str = ["red green blue";
"green red blue green blue"]
str = 2x1 string
"red green blue"
"green red blue green blue"
count returns 2 for the first string because red and blue each occur once. count returns 3 for the second string because red occurs once and blue occurs twice.