MATLAB: Searching cell arrays

cell arrays

I want to find the index of a cell array that contains a specific string, but the search and find functions don't take cell arrays as arguments. How do I return the cell number that contains the string?

Best Answer

Should the cell exactly match the specific string? If so then use ismember().
Should the cell member start with the specific string? If so then cellfun() and strncmp()
Should the cell member contain the specific string as a substring somewhere in it? If so then cellfun() and strfind() and isempty()
The matching process on a cellstr can also be done by regexp(); you might need to cellfun() isempty() to determine the logical result for each entry. It is, though, well suited to returning substring locations, and if you have time it would be worth reviewing regexp() as a serious possibility.