[Solved] For loops to take specific values only in MATLAB


@RodyOldenhuis basically answered your question, and I’m flattered he hasn’t made this into an actual answer!

Simply take your code and change the inner for loop index so that it matches the outer loop index. In other words, do this:

syms l %// Why are you doing this?
a = [0 1 0 0 1 0;1 1 1 0 1 1;1 0 0 0 1 1;1 1 1 0 0 1;0 1 1 0 1 1];
n = [2 1;1 1;1 1;1 1;2 1];

for l = 1:5 
    i = l; %// Change here - Remove second for loop
    %// ... [rest of your code here]
    %// Get rid of the break in this loop
    end 
    %// Removed break here too
end

0

solved For loops to take specific values only in MATLAB