How to delete nan from array

B=[nan 8 nan;6 nan nan;6 5 8] C=[nan 4 nan;4 nan nan;5 3 2]
Answer: B=[8 6 6 5 8] C=[4 4 5 3 2]

 Accepted Answer

Guillaume
Guillaume on 13 Jan 2015
Edited: Guillaume on 13 Jan 2015
B = B';
B = B(~isnan(B))';
C = C';
C = C(~isnan(C))';

3 Comments

You need a reassignment to B and C too in there:
B = B(~isnan(B))';
C = C(~isnan(C))';
Yes, not sure what I was thinking.
Why use '? Why not just B=B(~isnan(B))?

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 13 Jan 2015

Commented:

on 4 Aug 2022

Community Treasure Hunt

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

Start Hunting!