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)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!