Finding which rows in table contain NaN, save those as new table

198 ビュー (過去 30 日間)
new2matlab
new2matlab 2020 年 2 月 6 日
コメント済み: David Ebert 2022 年 10 月 3 日
Im looking to find a way to figure our which rows contain a 'NaN' in column 5, and then save all of those that do as a new table
  1 件のコメント
David Ebert
David Ebert 2022 年 10 月 3 日
Good question, same thing I'm trying to do.

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

採用された回答

Guillaume
Guillaume 2020 年 2 月 6 日
Assuming your input is a table:
nantable = yourtable(isnan(yourtable{:, 5}), :) %keep all rows whose 5th column is nan

その他の回答 (1 件)

Adam Danz
Adam Danz 2020 年 2 月 6 日
編集済み: Adam Danz 2020 年 2 月 7 日
If the tables all contain the same variable names (headers), use the variable names to index columns rather than column number. This is one of the strengths of tables over matrices and cell arrays. If the variable names are different, then you'll have to use numeric indexing.
Suppose column 5 is named "MyData" and the table is named "T".
nanIdx = isnan(T.MyData);
% If you must use numeric indexing,
% nanIdx = isnan(T{:,5});
Create the new table
Tnew = T(nanIdx,:);
  2 件のコメント
David Ebert
David Ebert 2022 年 10 月 3 日
Yes!
David Ebert
David Ebert 2022 年 10 月 3 日
Thanks!

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

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by