How to search for a string in cell array in MATLAB?

Benjamin picture Benjamin · Nov 9, 2011 · Viewed 171.6k times · Source

Let's say I have the cell array

strs = {'HA' 'KU' 'LA' 'MA' 'TATA'}

What should I do if I want to find the index of 'KU'?

Answer

Vidar picture Vidar · Nov 9, 2011

I guess the following code could do the trick:

strs = {'HA' 'KU' 'LA' 'MA' 'TATA'}
ind=find(ismember(strs,'KU'))

This returns

ans = 
     2