Most efficient way to generate combinations
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear all; I need to generate a large serie of combinations and it is taking a lot. I'm using 3 cycles one inside the other but I'm sure there's a better way to achieve this.
Here's what I'm currently doing:
indices=0; %indices matrix
l=1;
for i=1:200;
for j=1:300;
for k=1:250;
indices(l,1)=i-1;
indices(l,2)=j-1;
indices(l,3)=k-1;
l=l+1;
end
end
end
Please note that i, j and k have different lengths (thus values).
Any help would be greatly appreciated!
Thank you!
댓글 수: 0
답변 (3개)
Walter Roberson
2013년 4월 29일
[I, J, K] = ndgrid(0:199, 0:299, 0:249);
indices = horzcat(I(:), J(:), K(:));
댓글 수: 0
Jonathan Sullivan
2013년 4월 29일
a = (1:200)-1;
b = (1:300)-1;
c = (1:250)-1;
indices = allcomb(a,b,c);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!