Effacer les filtres
Effacer les filtres

How to remove/replace NaN from multiple variables in workspace?

7 vues (au cours des 30 derniers jours)
harshpurohit11
harshpurohit11 le 10 Oct 2018
Commenté : Stephen23 le 11 Oct 2018
I have a number of variables in workspace: A = [NaN; NaN; NaN; 1; 2; 3..]; B = [NaN; NaN; NaN; NaN; 4; 27; 31..]; C = [NaN; NaN; 10; 21; 34..]; et cetra and I need to replace NaNs from double with a 0.
  4 commentaires
madhan ravi
madhan ravi le 11 Oct 2018
See my answer below.
Stephen23
Stephen23 le 11 Oct 2018
"I have a number of variables in workspace: A... B... C ... et cetra and I need to replace NaNs from double with a 0."
Then you should redesign your code. Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know more:
<https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval

Connectez-vous pour commenter.

Réponses (1)

madhan ravi
madhan ravi le 10 Oct 2018
Modifié(e) : madhan ravi le 10 Oct 2018
An example:
>> A = [NaN; NaN; NaN; 1; 2; 3]
A(isnan(A))=0
A =
NaN
NaN
NaN
1
2
3
A =
0
0
0
1
2
3
>>

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by