Indexing a cell, ignoring empty inputs?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Titus Edelhofer
2015-3-24
编辑:Titus Edelhofer
2015-3-24
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
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!