Effacer les filtres
Effacer les filtres

Index 1 Variable by another

3 vues (au cours des 30 derniers jours)
Hillaryfor2016
Hillaryfor2016 le 12 Avr 2015
Commenté : Star Strider le 12 Avr 2015
Hi there!
I have 2 variables
if true
A = 1
2
NaN
4
end
B= 20
2
5
4
end
I want to remove the '5' from variable B by replacing it with a NaN (i.e. any NaN's in variable A result in a NaN in variable B
I understand this is a simple problem. I have researched but its been a long day Please help x

Réponse acceptée

Star Strider
Star Strider le 12 Avr 2015
Use ‘logical indexing’:
B(isnan(A)) = NaN
produces:
B =
20
2
NaN
4
  2 commentaires
Hillaryfor2016
Hillaryfor2016 le 12 Avr 2015
Worked beautifully, thanks for the help!! x
Star Strider
Star Strider le 12 Avr 2015
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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