Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by