Changing Array Elements with logical indexing

2 vues (au cours des 30 derniers jours)
MiauMiau
MiauMiau le 4 Avr 2014
Commenté : per isakson le 4 Avr 2014
Hi
If I want to change all NaNs in an array A to zero, the following works:
A(isnan(A))=1000
As far as I see the isnan(A) returns nothing but an array of 1's and 0's.
But if I do the following:
B = [ 1 5 8]; B([0 0 1]) = 1000;
to replace the 8 with a 1000, I get an error - why?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 4 Avr 2014
B = [ 1 5 8];
B(logical([0 0 1])) = 1000;
  2 commentaires
MiauMiau
MiauMiau le 4 Avr 2014
thx...then the result of the isnan are logical 1s and 0s?
per isakson
per isakson le 4 Avr 2014
Yes,
>> class( isnan( nan ) )
ans =
logical
>>

Connectez-vous pour commenter.

Plus de réponses (1)

TAB
TAB le 4 Avr 2014
B(B==8)=1000;

Catégories

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