adding or subtracting depending on the number
3 views (last 30 days)
Show older comments
jason on 8 Sep 2022
Answered: Walter Roberson on 8 Sep 2022
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.
David Hill on 8 Sep 2022
What have you tried? Can you explain yourself better through a code example?
Torsten on 8 Sep 2022
amount = 0.5;
variable = 5;
number = 1;
r = rand;
if r >= amount
variable = variable - number;
variable = variable + number;
Walter Roberson on 8 Sep 2022
Variable = Variable + sign(Threshold - RandomNumber) * amount
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!