delete the columns with the last two values equal to NAN

1 回表示 (過去 30 日間)
Qian cao
Qian cao 2015 年 12 月 21 日
編集済み: Image Analyst 2015 年 12 月 21 日
Hi all, I have a matrix
a=[1 NaN 1 1; 1 1 1 1; NaN NaN NaN 1;NaN NaN 1 NaN ]
How to do the function that deletes the columns whose last two values are NaN? So the a matrix here is expected to be
b=[1 1; 1 1; NaN 1; 1 NaN ]
after the first and second column are deleted from the matrix.
a =
1 NaN 1 1
1 1 1 1
NaN NaN NaN 1
NaN NaN 1 NaN
b =
1 1
1 1
NaN 1
1 NaN
Thank you very much.

採用された回答

Renato Agurto
Renato Agurto 2015 年 12 月 21 日
This should do it:
b = a(:, ~isnan(a(end-1,:)) | ~isnan(a(end,:)));
  1 件のコメント
Guillaume
Guillaume 2015 年 12 月 21 日
Alternatively,
b = a(:, ~all(isnan(a(end-1:end, :))));

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by