フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I want to change a variable with every iteration either randomly, how do i do that ?

1 回表示 (過去 30 日間)
Panth Patel
Panth Patel 2020 年 10 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Ameer Hamza
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 件のコメント
Panth Patel
Panth Patel 2020 年 10 月 24 日
編集済み: Panth Patel 2020 年 10 月 24 日
It works fine
Thank you very much !!!
Your help is very much appreciated.
Ameer Hamza
Ameer Hamza 2020 年 10 月 24 日
I am glad to be of help!!!

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by