Why aren't my if statements working

4 Ansichten (letzte 30 Tage)
Not_sharpest_tool.mat
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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Nov. 2018

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by