Indexing a cell, ignoring empty inputs?

2 vues (au cours des 30 derniers jours)
Thomas Koelen
Thomas Koelen le 24 Mar 2015
Commenté : Thomas Koelen le 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

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 24 Mar 2015
Modifié(e) : Titus Edelhofer le 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
  3 commentaires
Titus Edelhofer
Titus Edelhofer le 24 Mar 2015
Yes, of course. But I would start a new thread.
Titus
Thomas Koelen
Thomas Koelen le 24 Mar 2015
Ok I did that!
Thanks again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by