using strcmp on nested cell array (cell array within a cell array)
Show older comments
I need to retrieve the index of a string within a cell array where some cells are strings and others are cell arrays of different sizes. For example the first 5 rows might look like this:
{1×2 cell}
{'Text1' }
{1×2 cell}
{'Text2' }
{1×5 cell}
How do I retrieve the row index when the string might be contained with the cell arrays? I'd like to do this without a loop and I'm sure there's a way but I can't figure it out and can't seem to find an answer anywhere. I've tried cellfun which works if I was searching for 'Text1' for example.
Accepted Answer
More Answers (1)
Kevin Phung
on 24 Jan 2019
Edited: Kevin Phung
on 24 Jan 2019
if a is your cell array:
myText ='Text1';
idx = find(cellfun(@ischar,a)) %returns those indices where cell is a chr array
idx = idx(find(strcmp(a(cellfun(@ischar,a)),myText)))
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!