Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
I want to change a variable with every iteration either randomly, how do i do that ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ameer Hamza
am 22 Okt. 2020
Something like this will work
x = 0;
for i = 1:100
x = min(max(x + 2*(rand()>0.5)-1, -5), 5)
end
2 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!