필터 지우기
필터 지우기

for loop to generate all possible combination between N vectors without element repetition in result matrix

조회 수: 1 (최근 30일)
hi,
i am making a program to generate a matrix that include all possible combination between N vecotrs without any element repetition in any row
i made something like this
a=[1:37];
b=[1:37];
c=[1:37];
d=[1:37];
e=[1:37];
counter=1;
for i=1:37
for j=1:37
for k=1:37
for l=1:37
for m=1:37
SW=unique((sort((combvec(a(1:i),b(1:j),c(1:k),d(1:l),e(1:m))'),2)),'rows');
SW(any(diff(sort(SW,2),[],2)==0,2),:)=[];
counter=counter+1
end
end
end
end
end
i know i could do in one step without a for loop, but when the N vectors a,b,c,d,e lengthes and numbers increase (and it will in the future), it becomes out of memory error thats why i make a for loop
the problem is that the loop takes a very long time and i know its ordinary since in include many operation such as sorting and removing repetition in each iteration
but i want you guys to tell me if the code in the rigth form or is it include more useless steps which makes it take more time than it sould !!
take in consideration that the length of and number of N vectors may change in future and become more and taller

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by