Double Loop iterations doubt
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello,
I have a doubt about the possibility of having 2 loops going around in the same For. The code that I have is the following:
for i = 0:natts-1
fieldname = netcdf.inqAttName(ncid(j,:), netcdf.getConstant('NC_GLOBAL'),i);
fileinfo.(fieldname) = netcdf.getAtt(ncid,netcdf.getConstant('NC_GLOBAL'), fieldname );
end
And I would like to change the index on the ncid variable every time the initial index goes around 12 times. Is it possible to do such thing ? to have on index going up every time the first one does a 12 iteration loop ?
Thanks Rod
댓글 수: 0
채택된 답변
Matt Fig
2012년 8월 24일
편집: Matt Fig
2012년 8월 24일
Is this what you mean?
if ~mod(i,12)
j = j + 1;
end
I am assuming here that j is set outside the loop you show, and is NOT an index of an outer FOR loop. If it is the index of an outer FOR loop, you should instead set it like this:
for j = mod(0:48,12)+1 % Or whatever.
% Inner loop
end
Also, it is not recommended to mask MATLAB functions, such as the i and j function.
댓글 수: 2
Jan
2012년 8월 24일
I still think, that "i" and "j" should not be functions and even MLint suggests to use the 1i instead to get the imaginary value.
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!