erogol
erogol

Reputation: 13614

How to look up in a cell of Strings for existence of a specific string

Suppose I have a cell like

A = {'erogol' 'grerol' 'biral'}

then I want to search inside for a particular string.

Is there any special function doing it?

Upvotes: 1

Views: 89

Answers (1)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

One of the functions is strmatch:

    index = strmatch('grerol',A,'exact');

It returns an array of indexes. It is now deprecated, and Mathworks recommend using strcmp instead

    logicalIndexing = strcmp('grerol',A);

Another option is ismember :

    [bIsMember,index]=ismember('grerol',A);

Another option is strfind : indexes = strfind(A,'grerol');


Last but not least,

    booleanIndexes = cellfun(@(x)(isequal(x,'grerol')),A);

Upvotes: 3

Related Questions