Why aren't my if statements working
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Not_sharpest_tool.mat
el 23 de Nov. de 2018
Respondida: Walter Roberson
el 23 de Nov. de 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 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!