How to make a NaN vector if there is a single NaN in a column?

1 view (last 30 days)
Say you have a vector
A= [ 2 4 6 8 NaN 10 12 14]
How do you make a NaN vector if and only if there is a NaN in one of the columnns:
A = [NaN NaN NaN NaN NaN... ]

Accepted Answer

madhan ravi
madhan ravi on 28 Jul 2020
[m, n] = size(A);
A = nan(m, any(isnan(A(:))) * n)
  8 Comments
Cnell
Cnell on 28 Jul 2020
I thought the "if and only if" gave that away. Perhaps I should have been more clear, my apologies.
madhan ravi
madhan ravi on 28 Jul 2020
Sorry I’m not a mind reader:(
ix = nan(m, any(isnan(A(:)))* n);
if isempty(ix)
A = A
else
A = ix
end

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!