フィルターのクリア

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

1 回表示 (過去 30 日間)
Thomas Koelen
Thomas Koelen 2015 年 4 月 7 日
編集済み: Thomas Koelen 2015 年 4 月 7 日
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 件のコメント
Thomas Koelen
Thomas Koelen 2015 年 4 月 7 日
編集済み: Thomas Koelen 2015 年 4 月 7 日
Thanks, this answers my question. I made a for loop now to fill an array.

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by