こんにちは、私は 1D ランダム ウォーカーをプログラムしました。キャプチャ ゾーンを実装しようとしています。このゾーンでは、ウォーカーが特定の値の範囲内に一定時間留まるとプログラムが停止します。私が持っているコードは次のようになります。
steps = 1000; %sets the number of steps to 1000
rw = cumsum(-1 + 2 * round(rand(steps,1)),1); %Set up our random walk with cumsum
%Now we will set up our capture zone between 13-18 for fun
if rw >= 13 & rw <= 18
dwc = dwc + 1 %Dwelling counted ticks up every time walker is in 13-18
else dwc = 0; %Once it leaves, it returns to 0
end
while dwc >= 5
fprintf('5 steps or more within range after %d steps, so so breaking out.\n', rw);
break
end
figure(7)
comet(rw); %This will plot our random walk
grid on; %Just to see the capture zone better
hold on;
line(xlim, [13, 13], 'Color', 'r');
line(xlim, [18, 18], 'Color', 'r');
hold off;
title('1d Random Walk with Capture Zone');
xlabel('Steps');
ylabel('Position');
ウォークスルーしますが、攻略ゾーンでブレイクすることはありません。複数の機会に 5 ステップ以上キャプチャ ゾーンにあったと確信していますが、とにかく実行し続けます。どんな助けでも大歓迎です。