Indexing a cell, ignoring empty inputs?

4 次查看(过去 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

采纳的回答

Titus Edelhofer
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 个评论
Titus Edelhofer
Titus Edelhofer 2015-3-24
Yes, of course. But I would start a new thread.
Titus

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by