Effacer les filtres
Effacer les filtres

How to remove NaN from 2 column vectors?

4 vues (au cours des 30 derniers jours)
IMC
IMC le 12 Juil 2021
Commenté : IMC le 12 Juil 2021
Hi everyone,
I have 2 column vectors with 12 values each:
X = [2 4 8 NaN 13 NaN 3 6 NaN 38 40 11]
Y = [NaN NaN 2 NaN 10 67 1 NaN NaN 19 26 NaN]
I want to remove NaN from these vectors such that if first NaN from Y is removed value '2' from X also gets removed. Similarly if any NaN from X is removed respective value from Y also gets removed.
Kindly suggest me how to do this. Thank you

Réponse acceptée

Scott MacKenzie
Scott MacKenzie le 12 Juil 2021
Modifié(e) : Scott MacKenzie le 12 Juil 2021
X = [2 4 8 NaN 13 NaN 3 6 NaN 38 40 11];
Y = [NaN NaN 2 NaN 10 67 1 NaN NaN 19 26 NaN];
nanLogical = isnan(X) | isnan(Y);
X(nanLogical) = []
X = 1×5
8 13 3 38 40
Y(nanLogical) = []
Y = 1×5
2 10 1 19 26

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by