Info
此问题已关闭。 请重新打开它进行编辑或回答。
I want to change a variable with every iteration either randomly, how do i do that ?
1 次查看(过去 30 天)
显示 更早的评论
I want to change a variable with every iteration either by +1 or -1 randomly and keep the overall variable in between +5 to -5
0 个评论
回答(1 个)
Ameer Hamza
2020-10-22
Something like this will work
x = 0;
for i = 1:100
x = min(max(x + 2*(rand()>0.5)-1, -5), 5)
end
2 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!