Indexing a cell, ignoring empty inputs?
3 views (last 30 days)
Show older comments
Thomas Koelen
on 24 Mar 2015
Commented: Thomas Koelen
on 24 Mar 2015
I have a cell that looks like this:
'GS_L' 'OECF' 'DYNAMIC_RANGE'
'GS_R' 'OECF' 'DYNAMIC_RANGE'
'GS_U' 'OECF' 'DYNAMIC_RANGE'
'GS_D' 'OECF' 'DYNAMIC_RANGE'
'HOR_B' 'UNIFORMITY' '0'
'HOR_W' 'UNIFORMITY' '0'
'HOR_G' 'UNIFORMITY' '0'
'VER_B' 'UNIFORMITY' '0'
'VER_W' 'UNIFORMITY' '0'
'VER_G' 'UNIFORMITY' '0'
I want to take the first row of the cell that have the word OECF in it.
So I apply this:
OECFINDEX = strfind(measureables,'OECF');
Which gives:
[] [1] []
[] [1] []
[] [1] []
[] [1] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
Now I do this:
OECFMES = measureables(find([OECFINDEX{:}] == 1)',1);
Which gives me:
'GS_L'
'GS_R'
'GS_U'
'GS_D'
Now, this seems to be working but when I try it for UNIFORMITY,
UNIFORMITYMES = measureables(find([UNIFORMITYINDEX{:}] == 1)',1);
It shows:
'GS_L'
'GS_R'
'GS_U'
'GS_D'
'HOR_B'
'HOR_W'
Instead of
'HOR_B'
'HOR_W'
'HOR_G'
'VER_B'
'VER_W'
'VER_G'
Does it ignore empty cell inputs? Or what is going on, and is there a way to fix this?
Kind regards,
Thomas Koelen
0 Comments
Accepted Answer
Titus Edelhofer
on 24 Mar 2015
Edited: Titus Edelhofer
on 24 Mar 2015
Hi Thomas,
yes it does. Do you really look for OECF in each string, or do you want to compare to OECF? For your example at least, the following works better:
UNIFORMITYINDEX = strcmp(measureables(:,2), 'UNIFORMITY')
measureables(UNIFORMITYINDEX, 1)
ans =
'HOR_B'
'HOR_W'
'HOR_G'
'VER_B'
'VER_W'
'VER_G'
Note, that I used strcmp instead of strfind. Don't know if that fit's only this example, though...
If strmatch is indeed the right function, use cellfun:
measureables(~cellfun(@isempty, UNIFORMITYINDEX(:,2)), 1)
Titus
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!