Clear Filters
Clear Filters

a question on inner loops

1 view (last 30 days)
Mnr
Mnr on 7 Mar 2016
Answered: John D'Errico on 7 Mar 2016
Hello all,
I would like to have 2 for loops such that the outer 1 counts i=1:M and the inner one from j=1:M but j~=i. How can I program this in Matlab? In other words, I would like to have something like
if true
for i=1:M
for j=1:M && j~=i
code
end
end
end

Accepted Answer

John D'Errico
John D'Errico on 7 Mar 2016
Easy.
for j = setdiff(1:M,i)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!