Effacer les filtres
Effacer les filtres

How to extract NaN values from matrix?

7 vues (au cours des 30 derniers jours)
studentmatlaber
studentmatlaber le 14 Avr 2022
Commenté : the cyclist le 14 Avr 2022
Hello to everyone. I have a 28x5 matrix and this matrix has NaN values in it. I want to create a new matrix by deleting these NaN values from my matrix. My new matrix should only consist of numbers. I also want to save the newly formed matrix as a 1-line vector. How can I do that.
I wrote a code like this to delete NaN values, but I couldn't get the right result. Thanks for your help.
x_T_est1n=x_T_est1(~isnan(x_T_est1(:,1))&~isnan(x_T_est1(:,2)),:);%NANs

Réponse acceptée

the cyclist
the cyclist le 14 Avr 2022
Here are two different ways:
M = [2 3;
5 NaN];
Mvec = M(not(isnan(M)))'
Mvec = 1×3
2 5 3
Mvec2 = M;
Mvec2(isnan(Mvec2)) = []
Mvec2 = 1×3
2 5 3
  2 commentaires
studentmatlaber
studentmatlaber le 14 Avr 2022
Modifié(e) : studentmatlaber le 14 Avr 2022
Thank you for your answer. There is one point that comes to my mind. matrix M = [2 3;5 NaN]. After removing the NaN value in this vector and creating the vector, it became 2 5 3 . However, the matrix I wanted should have been 2 3 5 . In other words, after writing the values in the 1st line and finishing, he should have written the values in the 2nd line.
the cyclist
the cyclist le 14 Avr 2022
M = [2 3;
5 NaN];
Mvec2 = M';
Mvec2(isnan(Mvec2)) = []
Mvec2 = 1×3
2 3 5

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations 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