How can I identify the indices of rows containing all NaNs from matrix?

15 ビュー (過去 30 日間)
Deepa T
Deepa T 2017 年 5 月 31 日
コメント済み: Star Strider 2017 年 6 月 1 日
I have very large matrices, in which some rows contain all NaN. I don't want to remove these rows. But I wish to identify which index contains all NaN. I have seen code for removing such rows, but how can I extract the index value?
I am not very familiar with MATLAB. Thanks in advance.

採用された回答

Star Strider
Star Strider 2017 年 5 月 31 日
Try this:
M = [rand(3,5); NaN(1,5); rand(4,5); NaN(1,5); rand(2,5)]; % Create Data
NaN_rows = find(all(isnan(M),2)); % Identify ‘NaN’ Rows By Index
  2 件のコメント
Deepa T
Deepa T 2017 年 6 月 1 日
Thank you very much. This is exactly what i wanted to do.
Star Strider
Star Strider 2017 年 6 月 1 日
As always, my pleasure!

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

その他の回答 (1 件)

Chandrasekhar
Chandrasekhar 2017 年 5 月 31 日
% idenfity NaN's in the matrix
k = isnan(a);
% find the indices of NaN's
find(k==1);
  1 件のコメント
Deepa T
Deepa T 2017 年 6 月 1 日
Thank you for your reply. This query helps me to identify every NaN in the dataset, not just the rows with all NaN.

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

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by