adding or subtracting depending on the number
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I make it so that if a random number is above a certain amount a number will be subtracted from a diffrent variable. But if the random number is below a certain amount it will be added to a variable.
1 commentaire
David Hill
le 8 Sep 2022
What have you tried? Can you explain yourself better through a code example?
Réponses (2)
Torsten
le 8 Sep 2022
rng ("default")
amount = 0.5;
variable = 5;
number = 1;
r = rand;
if r >= amount
variable = variable - number;
else
variable = variable + number;
end
variable
0 commentaires
Walter Roberson
le 8 Sep 2022
Variable = Variable + sign(Threshold - RandomNumber) * amount
0 commentaires
Voir également
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!