フィルターのクリア

How to use the index ? how to drop elements from a matrix ?

4 ビュー (過去 30 日間)
Islam
Islam 2013 年 11 月 30 日
回答済み: Andrei Bobrov 2013 年 11 月 30 日
I have a matrix b(j,w) = b(3,4)
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
and g(j,w)=g(3,4)
60 60 60 60
70 70 70 70
75 75 75 75
I want to drop the elements in g that have a correspondent NAN value in b.

採用された回答

Wayne King
Wayne King 2013 年 11 月 30 日
編集済み: Wayne King 2013 年 11 月 30 日
One of many ways:
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
idx = ~isnan(b);
g = g(idx>0);

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 30 日
b= [ 0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
c=[ 60 60 60 60
70 70 70 70
75 75 75 75]
idx=any(~isnan(b),1)
c=c(:,idx)

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 30 日
b = [0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
>> g(~isnan(b))
ans =
60
70
75

カテゴリ

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