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

1 vue (au cours des 30 derniers jours)
Cnell
Cnell le 28 Juil 2020
Commenté : madhan ravi le 28 Juil 2020
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... ]

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by