MATLAB: Return the number of rows of an array of cell data

findMATLAB

I have an array of cell data “a” in Matlab. I want to look at the array (which contains numeric and text data) and say in Matlab speak: Find what row of “a” says: ‘Temp Height (density)’.
The Code will return b=1326; I was thinking something like:
[row,col] = find(a, {Temp Height (density)});
This will then give me the value row=1326 which is what I need. I tried to use the find function but it doesnt seem to work becasue it tells me: Undefined function or method 'find' for input arguments of type 'cell'.
Help on this is much appreciated.

Best Answer

If your cell contains strings (and not numeric data), just use strcmp:
[row,col] = find(strcmp('Temp Height (density)', a));
If some elements of your cell are numeric, the above will fail ( UPDATE: Actually, the above works fine even for non-char elements... I'll leave the rest of my answer for reference). Another method uses the cell function below:
[row,col] = find(cellfun(@(c)ischar(c)&&strcmp('Temp Height (density)',c),a))
or do it in two steps:
strInds = find(cellfun(@ischar, a));
matchMask = strcmp('Temp Height (density)'), a(strInds));
[row,col] = ind2sub(size(a), strInds(matchMask));