I'm writing a script to simulate the movement of some particles, so I'm working with discrete timesteps i in a for-loop. Inside this loop, I have another for-loop to change position etc. of every particle k. Now, I want to check for every k if there is any of the other particles (for loop over particle j) wich comes too close because than both will annihilate(disappear) which means the new position etc. for k (and j) doesn't need to be computed anymore.
So my question is: how do I check FOR every 1<k<m IF there exist a 1<j<m, j~=k which satisfies certain requirements and IF that's the case move on directly to k+1? ELSE, so if there's no j with the requirements for this k, proceed to the calculation of r(k,i+1)... via a specific algorithm before going to particle k+1.
for i=1:n %timestep
for k=1:m %particle
if isnan(rx(k,i))==1 %I'm checking if it still exists, if not don't do anything and go to the next k
else
for j=1:m %other particles
if isnan(rx(j,i))==0 %check if it still exists
if j~=k
d(k,j)=(rx(k,i)-rx(j,i))^2+(ry(k,i)-ry(j,i))^2;
if d(k,j)<1.5*z0 && s(k)+s(j)==0 %IF THAT'S THE CASE I WANT TO INCREASE K BY ONE IMMEDIATELY
end
... some other stuff about interaction k and j...
end
... some more irrelevant stuff...
end
end
end
... calculate rx(k,i+1) etc ...
end
end
end

3 件のコメント

dpb
dpb 2014 年 3 月 12 日
Would be far simpler if had the basic code to look at, but sounds like you're looking for
doc continue % you may find _break_ of interest, too...
Wouter
Wouter 2014 年 3 月 13 日
@dpb if I try continue, it just moves to the next j but I want to the next k. And if I try break, it moves to the rest of the code behind the j-loop but still for that k.
Patrik Ek
Patrik Ek 2014 年 3 月 13 日
編集済み: Patrik Ek 2014 年 3 月 13 日
while j<some_value && condition?

サインインしてコメントする。

 採用された回答

Chris C
Chris C 2014 年 3 月 13 日

0 投票

You need to break out of the j-loop upon that condition and then condition a continue statement within the k-loop.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

製品

タグ

質問済み:

2014 年 3 月 12 日

回答済み:

2014 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by