any returns 0 eventhough there is a non zero element in the row

1 次查看(过去 30 天)
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?

采纳的回答

Thorsten
Thorsten 2015-4-7
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 个)

Star Strider
Star Strider 2015-4-7
I believe you’re using the wrong syntax with any.
Consider:
OECFINDEX = [0 0 1 0];
OECFINDEX = any(OECFINDEX)
produces:
OECFINDEX =
1

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by