Remove a column if it starts with NaN

2 ビュー (過去 30 日間)
Olga
Olga 2014 年 8 月 27 日
コメント済み: Guillaume 2014 年 8 月 27 日
Could you please help me find a way to remove a entire column of a matrix if it starts with Nan
Thank you for any help!

回答 (3 件)

Guillaume
Guillaume 2014 年 8 月 27 日
m(:, isnan(m(1, :))) = [];

Image Analyst
Image Analyst 2014 年 8 月 27 日
Try this:
A = [1 nan 3 nan;
1 5 6 0;
2 2 3 4;
2 5 6 0;
2 6 7 8;
3 1 2 3;
4 1 2 3]
badColumns = isnan(A(1,:)) % Find cols with nan in top row.
fixedA = A(:,~badColumns) % Get all except the bad columns.

Olga
Olga 2014 年 8 月 27 日
Thank you very much! It worked!
  1 件のコメント
Guillaume
Guillaume 2014 年 8 月 27 日
Whichever answer worked best for you (they're both valid), you should accept. (and you should have commented on instead of creating a new answer)

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

カテゴリ

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