I am doing an n body simulation, and I want to be able to skip a line in my function?

1 view (last 30 days)
So I need to calculate separations and then accelerations for n bodies, so in my function im using for ODE45 I have for i = 1:N for j = 1:N %calculate separations in x and y %calculate separation magnitude %calculate accelerations in x and y end
and obviously I don't want to calculate it when i = j so I was wondering if there was a way I could skip these loops. I was assuming using if statements but im not sure what will actually tell it to skip

Accepted Answer

John D'Errico
John D'Errico on 17 Nov 2015
Just do this:
if i ~= j
put your stuff inside here, that only applies for i and j not equal
end
  1 Comment
BigD
BigD on 17 Nov 2015
Aha, I realised this after i'd posted the question and feel a bit silly now, but thank you very much for responding :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!