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?
0 件のコメント
採用された回答
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
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
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!