
怎么选择数组里两个元素的所有组合
1个回答
展开全部
用个循环就可以了
a=input('Please enter the vector a:');
j=length(a);
i=1;
b=[];
%Get all the possible combinations;
for m=1:j-1
for n=m+1:j
b(i,:)=[a(m) a(n)];
i=i+1;
end
end
disp(b);
a=input('Please enter the vector a:');
j=length(a);
i=1;
b=[];
%Get all the possible combinations;
for m=1:j-1
for n=m+1:j
b(i,:)=[a(m) a(n)];
i=i+1;
end
end
disp(b);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询