Indexing a cell, ignoring empty inputs?
2 ビュー (過去 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 で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!