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'
?
I see that everybody missed the most important flaw in your code:
strs = {'HA' 'KU' 'LA' 'MA' 'TATA'}
should be:
strs = {'HA' 'KU' 'NA' 'MA' 'TATA'}
or
strs = {'HAKUNA' 'MATATA'}
Now if you stick to using
ind=find(ismember(strs,'KU'))
You'll have no worries :).
Other answers are probably simpler for this case, but for completeness I thought I would add the use of cellfun with an anonymous function
indices = find(cellfun(@(x) strcmp(x,'KU'), strs))
which has the advantage that you can easily make it case insensitive or use it in cases where you have cell array of structures:
indices = find(cellfun(@(x) strcmpi(x.stringfield,'KU'), strs))
did you try
indices = Find(strs, 'KU')
see link
alternatively,
indices = strfind(strs, 'KU');
should also work if I'm not mistaken.