Basic question regarding adding A to all numbers greater than B

9 vues (au cours des 30 derniers jours)
Angel
Angel le 1 Fév 2018
Commenté : Angel le 1 Fév 2018
For example, if I have an array like x = (1:10); How would I add 2 to each number in that array that is greater than 5?

Réponses (1)

James Blackwell
James Blackwell le 1 Fév 2018
You could have an if function and go through the array element by element. If the number is greater than 5 you could add 2 to it :)
It sounds a bit like a homework question, so I don't think I'm supposed to give the code.
  3 commentaires
Steven Lord
Steven Lord le 1 Fév 2018
Since your homework assignment prohibits using if, its purpose is likely to familiarize you with logical indexing.
Angel
Angel le 1 Fév 2018
I'll look into that, thank you!

Connectez-vous pour commenter.

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