adding or subtracting depending on the number
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Torsten
2022-9-8
rng ("default")
amount = 0.5;
variable = 5;
number = 1;
r = rand;
if r >= amount
variable = variable - number;
else
variable = variable + number;
end
variable
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!