FUNCTION REFERENCE
count
Count occurrences of patterns in text.
Count occurrences of patterns in text.
Syntax
n = count(str, pat)Syntax
n = count(str, pat, 'IgnoreCase', flag)str is a character vector, cellstr or string array; pat is text or a list of patterns. The text is scanned from left to right; at each position the patterns are tried in order and a match consumes its characters, so a segment is counted at most once. n is a double array with the shape of str (a character vector counts as one element); missing strings count 0 and empty patterns never match.
Example
count("the cat sat on the mat", "at") % 3Example
count({'aaaa', 'abab'}, 'aa') % [2 0]Example
count('abcabc', {'bc', 'a'}) % 4Example
count("Hello hello", "hello", 'IgnoreCase', true) % 2Differences from MATLAB: pattern objects (digitsPattern etc.) are not supported.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.