I want to create a for loop which creates different pairs each time.
1 次查看(过去 30 天)
显示 更早的评论
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
3 个评论
Greig
2015-3-5
See Akshata's response below for how to structure the if statement.
As a general rule of good practice, it is better to avoid using i and j and loop indices, MATLAB reserves these for complex numbers (i.e., sqrt(-1)). Use ii and jj instead
采纳的回答
Chandrasekhar
2015-3-5
编辑:Chandrasekhar
2015-3-5
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!