any returns 0 eventhough there is a non zero element in the row
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Thomas Koelen
il 7 Apr 2015
Modificato: Thomas Koelen
il 7 Apr 2015
I have a cell that looks like this:
measureables =
'GS_L' 'OECF' 'DYNAMIC_RANGE' 'NOISE'
I do this:
OECFINDEX = strcmp(measureables(:,:),'OECF');
which gives:
ans =
0 1 0 0
now I do this:
OECFINDEX = OECFINDEX(:,any(OECFINDEX));
which should give (correct me if I'm wrong): 1
but the answer is 0.
It does work for larger cells that look like this:
measureables =
measureables =
'GS_L' 'OECF' 'DYNAMIC_RANGE' 'NOISE'
'GS_L' 'OECF' 'DYNAMIC_RANGE' 'NOISE'
'GS_L' 'OECF' 'DYNAMIC_RANGE' 'NOISE'
'GS_L' 'DYNAMIC_RANGE' 'NOISE'
here the program gives me:
1
1
1
0
why is not working for a single column?
0 Commenti
Risposta accettata
Thorsten
il 7 Apr 2015
Because it's just a vector (or 1 x N matrix),
any(OECFINDEX)
returns a single number, namely 1 in your example, and because OECFINDEX has just one row,
OECFINDEX(:,any(OECFINDEX))
is the same as
OECFINDEX(:,1);
or
OECFINDEX(1)
which is 0 in your case.
1 Commento
Più risposte (1)
Star Strider
il 7 Apr 2015
I believe you’re using the wrong syntax with any.
Consider:
OECFINDEX = [0 0 1 0];
OECFINDEX = any(OECFINDEX)
produces:
OECFINDEX =
1
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!