MATLAB: I want to create a for loop which creates different pairs each time.

for loop

for i=1:p
for j=1:p
i~=j
disp('i is equal to');
disp(i);
disp('j is equal to');
disp(j);
end
end
I have made this however some pairs are the same e.g i= 1 j = 1 and so on

Best Answer

  • for i=1:p
    for j=1:p
    if (i~=j)
    disp('i is equal to');
    disp(i);
    disp('j is equal to');
    disp(j);
    end
    end
    end