How to automize removal of NaN's for a structure?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yago Molano Gomez
le 7 Avr 2020
Réponse apportée : Walter Roberson
le 7 Avr 2020
Hello! I have some NaN's in my structure, and have tried various things but what I've gotten to work, in order to change them to zero is the following:
CL.i0(isnan(CL.i0)) = 0;
CL.i1(isnan(CL.i1)) = 0;
CL.i2(isnan(CL.i2)) = 0;
CD.i0(isnan(CD.i0)) = 0;
CD.i1(isnan(CD.i1)) = 0;
CD.i2(isnan(CD.i2)) = 0;
CM.i0(isnan(CM.i0)) = 0;
CM.i1(isnan(CM.i1)) = 0;
CM.i2(isnan(CM.i2)) = 0;
Is there any way to change this to automize it for future code?
Thanks in advance guys.
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Avr 2020
You can adapt the code I posted at https://www.mathworks.com/matlabcentral/answers/514678-how-do-i-remove-all-fields-of-a-structure-that-have-at-least-one-nan
In restricted cases where the structure fields are guaranteed to be simple data types, then you can use much smaller code.
structfun(@(F) fillmissing(F, 'constant', 0), CL, 'uniform', 0)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures 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!