MATLAB Answers

0

how can i remove efficiently nan values from columns without deleting the column itself ?

Asked by pavan sunder on 21 Oct 2016
Latest activity Answered by Andrei Bobrov
on 21 Oct 2016
for ex :
A = 1 2 3
nan 4 nan
nan nan 5
4 5 6
required output
A = 1 2 3
4 4 5
5 6

  1 Comment

Your posted matrix result is not rectangular. You can't have this in a numeric matrix. Is this really what you want for an output or is this a typo? I.e., do you really want the resulting columns to potentially have different numbers of elements? (In which case maybe a cell array would be what you want).

Sign in to comment.

Tags

1 Answer

Answer by Andrei Bobrov
on 21 Oct 2016

i0 = ~isnan(A);
ii = sort(i0,'descend');
out = nan(size(A));
out(ii)=A(i0);

  0 Comments

Sign in to comment.