필터 지우기
필터 지우기

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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by