好,这是我的简单代码,
for ii = 1:3;
for kk = 1:3;
if ii~=kk
z=ii+kk
end
end
end
我得到了输出,
1 + 2 = 3和2 + 1 = 3
与其他组合
我只想要其中一个,也不希望它告诉我相同的答案。
答案 0 :(得分:2)
以下内容:
for ii = 1:3;
for kk = (ii+1):3; % start from ii+1 as the others have already been calculated
% if ii~=kk we dont need it anymore
z=ii+kk
%end
end
end