mHelpMe
mHelpMe

Reputation: 6668

search for string in cell and return index number

I have a 20 x 2 cell. Both columns contains strings. What I would like to do is search for a string in column two and where the value in column 2 matches my search string to return the index number.

name         region          
ABC          USA
ASD          EU
PLKDD        EU
ERT          EU
LKK          ASIA
MNN          USA
WER          EU

The result I would like based on the search string being "EU" is below

result
2
3
4
7

Upvotes: 0

Views: 68

Answers (1)

kyamagu
kyamagu

Reputation: 551

Just use strcmp and find.

index = find(strcmp(value(:, 2), 'EU'))

Upvotes: 4

Related Questions