strmatch

Finds rows or cells that begin with the given text (legacy function).

Category: Language Fundamentals > Data Types

Syntax

k = strmatch(str, A)

Returns the indices of the rows of A that begin with str.

k = strmatch(str, A, 'exact')

Requires the entire row (ignoring trailing blanks) to equal str.

Description

strmatch was replaced by startsWith for prefix tests and by strcmp for exact comparisons, and it is kept only so that old code still runs. Matching is case sensitive. In the default mode a row matches when it starts with str.

New code should use find(startsWith(A, str)).

Input arguments

str
Text to look for.
A
Character matrix or cell array of character vectors.

Output arguments

k
Column vector of the matching row indices; empty if none match.

Example

Prefix and exact match

x = strmatch('ap', {'apple'; 'april'; 'bread'})
y = strmatch('apple', {'apple', 'apple pie'}, 'exact')
z = strmatch('ap', ['apple'; 'bread'])
Output
x = 2×1

     1
     2
y = 1
z = 1

See also

startsWith strcmp strncmp find contains