MATLAB Answers

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

14 views (last 30 days)
Deepa T
Deepa T on 31 May 2017
Commented: Star Strider on 1 Jun 2017
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.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 31 May 2017
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

More Answers (1)

Chandrasekhar
Chandrasekhar on 31 May 2017
% idenfity NaN's in the matrix
k = isnan(a);
% find the indices of NaN's
find(k==1);

  1 Comment

Deepa T
Deepa T on 1 Jun 2017
Thank you for your reply. This query helps me to identify every NaN in the dataset, not just the rows with all NaN.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!