Effacer les filtres
Effacer les filtres

How to change Nan value with zero and return them again?

1 vue (au cours des 30 derniers jours)
Ayob
Ayob le 24 Jan 2014
Commenté : Amit le 24 Jan 2014
I have a matrix like A which some of its members are NAN. I want to do some mathematical works on it, but I can not do it because of nan values. So I decided to change these nan values to zero and after finishing mathematical works return Nan to the same places( my matrix dimension doesn't change during the job.)
for example:
B=A.^(0.5) [it doesn't work because of nan values in A]
I should find nan values and replace them with zero to build a new A.
Now I use A.^0.5 with the A built in the last step for B=A.^2
I have B with the same dimension of A, I should return nan values to the same place of B which were replaced with zero in A.
How can I do it with Matlab features?
[I don't want to replace all zero values in B, I want to replace zero values in B which there were nan values in the similar position of A.] N

Réponse acceptée

Amit
Amit le 24 Jan 2014
Ind = find(isnan(A));
A(ind) = 0;
B = A.^0.5;
B(ind) = NaN;
  1 commentaire
Amit
Amit le 24 Jan 2014
BTW, A.^0.5 would work even for NaN values.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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