Simplifying a large nested for-loop
이전 댓글 표시
I am trying to simplify a nested for-loop. Any suggestions would be highly appreciated!
The structure of the problem in its crudest form is the follows:
comb=zeros(1,N); %where N is a large number like 100
comb(1)=1;
for m2=1:N2 %where N2 is some predetermined number
comb(2)=IX(m2,2); %where IX is some pre-determined matrix
if consistent(comb) %where consistent(x) is a pre-specified fcn
for m3=1:N3
comb(3)=IX(m3,3);
if consistent(comb)
for m4=1:N4
comb(4)=IX(m4,4);
if consistent(comb)
...... %this needs to be continued in exactly the same fashion until I reach the (N-1)th nested loop
for mN=1:NN
comb(N)=IX(mN,N);
if consistent(comb)
tot_dist=min(tot_dist(comb),tot_dist) %where tot_dist(x) is a pre-specified fcn
else
end
end
......
else
end
end
else
end
end
else
end
end
The basic problem is conceptually the same as this: start from a vector comb=(1,0,...0). Select a number out of N2 numbers to fill the comb(2) if that selection satisfies some consistency condition. Do this for each of the remaining N-2 entries in comb, but the consistency condition is path dependent in the sense that your selection for comb(2) affects the consistency of a proposed selection for comb(3). Finally i need to select among all legitimate comb's the one that minimizes some total distance criterion.
Is there a way to handle this type of problems? Thank you very much in advance!
Yu
댓글 수: 4
Naz
2011년 11월 15일
The algorithm is just terrible. May be there is another way of doing it instead of loops? Do you have a general equation for it?
Yu
2011년 11월 15일
Yu
2011년 11월 15일
Daniel Shub
2011년 11월 15일
The comments section does not allow formatting. You could edit your question with this information.
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!