I explained all() about it already .
Why aren't my if statements working
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!