作业帮 > 英语 > 作业

matlab 排列组合问题

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/09 19:30:14
matlab 排列组合问题
从10个数(1到10)中选3个数.其中1和2不能同时出现,3和4不能同时出现
%----如果楼主想获得个数,在结尾加一句 size(c,1)就好--------------
a = 1:10;
c = nchoosek(a,3); %10 numbers taken 3 at a time
rowIndex = [];
%--------find row index of including 1,2 or 3,4 simultaneously-----------
for i=1:size(c,1)
if size(find(c(i,:)==1|c(i,:)==2),2)==2|size(find(c(i,:)==3|c(i,:)==4),2)==2
rowIndex = [rowIndex,i];
end
end
%--------delete the correspond rows----------------------------
c(rowIndex,:)=[];
disp(c);