Why aren't my if statements working
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Not_sharpest_tool.mat
am 23 Nov. 2018
Beantwortet: Walter Roberson
am 23 Nov. 2018
This program is a 1d random walk. The random walk works. The walker is supposed to reflect or bounce inside a range (-10 to 10). I used an if statement for this. But my if statements dont work at all. Its as if the statements didnt exist at all. The program behaves the same whether I have it or not. There has to be a mistake in my code. Please help.
iterations= 1;
Num_steps = 1000;
Random_steps_r = NaN(Num_steps,iterations);
for i = 1:iterations
Random_steps_r(:,i) = cumsum(-1 + 2 * round(rand(Num_steps,1)),1);
end
x=Random_steps_r;
deltax=diff(x);
xMax=10;
xMin=-10;
if all(x(1:999)+deltax>xMax)
x=xMax-(x+deltax-xMax);
elseif all(x(1:999)+deltax<xMin)
x=xMin-(x+deltax-xMin);
end
comet(x)
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!