remove the NaN numbers from a matrix without loop

1 回表示 (過去 30 日間)
Noushin Farnoud
Noushin Farnoud 2011 年 11 月 28 日
Hello Matlab Users,
In my matrix of NxD dimension, I know that the number of NaNs on each row are the same, however the position of these NaN elements differ between rows. Is there an efficient way to remove NaN's from this matrix while keeping the shape of matrix, as shown in the simplified example:
A=[ 1 2 3 NaN 4 5 NaN; 6 NaN 7 8 NaN 9 10]
and I would like to be able to remove NaNs and get:
A_mod=[ 1 2 3 4 5; 6 7 8 9 10]
I appreciate your help, NF

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 28 日
At = A.';
A_mod = reshape(At(~isnan(At)),[],size(A,1)).';

その他の回答 (1 件)

bym
bym 2011 年 11 月 28 日
A_mod = A(~isnan(A)); %untested
  3 件のコメント
bym
bym 2011 年 11 月 28 日
right
Noushin Farnoud
Noushin Farnoud 2011 年 11 月 29 日
Thank you so much Walter. This worked perfectly!

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

カテゴリ

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