Hello! Please, how can I implement an iteration, such that a first loop executes a series of expressions within a range of (32) values and a second loop executes a series of expressions within another range of(16) values for each result of the first iteration. the result of this would be 512 iterations. Thank u.

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 3월 31일
Are the values independent or does the first loop need to complete before the second loop could start?

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2011년 3월 31일

0 개 추천

I guess you mean nested loops?
for ni=1:32
for nj=1:16
% Do something here?
end
end

댓글 수: 4

Walter Roberson
Walter Roberson 2011년 3월 31일
Or maybe
parfor ni=1:32
for nj=1:16
%do something here?
end
end
But that presumes that each if the nj loops does not need results from a different ni loop, a point I explicitly questioned.
Depending what exactly has to be done, this might even be a case for co-distribution using for ni = drange(1:32)
God'sSon
God'sSon 2011년 3월 31일
thanks, but for my code, the nj loops needs the results from the ni loop. ie, after the ni loop completes its 32 iterations, the nj loop should perform 16 iterations for each of the 32 results from ni.
Walter Roberson
Walter Roberson 2011년 3월 31일
parfor ni=1:32
%do first thing here
end
parfor ni=1:32
for nj=1:16
%do second thing here
end
end
It would, though, not surprise me if the first parfor would be more efficient as a for loop -- depends how much work is done in the first part.
God'sSon
God'sSon 2011년 3월 31일
I did away with the parfor loops and got it running using only for-loops in all the cases.
Thanks u very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2011년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by