Jump to next loop (alternative goto)

조회 수: 8 (최근 30일)
BdS
BdS 2019년 3월 27일
댓글: BdS 2019년 3월 27일
Hi,
my code is mentioned below. The question is green after % if statement. May you help me?
function NewRanks=createRebRankings(f_Ranks,RebRanks,RebIndi)
nDates=size(f_Ranks,1);
nRebDates=size(RebRanks,1);
nRebIndi=length(RebIndi);
nFactors=size(f_Ranks(1,1,:),3);
nInstr=size(f_Ranks(1,:,1),2);
NewRanks=NaN(nDates,nInstr,nFactors);
for f=1:nFactors
NewRanks(1,:,f)=f_Ranks(1,:,f);
for d=2:nDates
for i=2:nRebIndi
if RebIndi(i)==0
NewRanks(d,:,f)=NewRanks(d-1,:,f);
else
for n=2:nRebDates
NewRanks(d,:,f)=RebRanks(n,:,f);
end %nRebDates
end % if statement --> After the excecution of the if statement I would like matlab to jump to d=2:nDates instead to i=2:nRebIndi.
end % nRebIndi
end % nDates
end % nFactors
  댓글 수: 2
madhan ravi
madhan ravi 2019년 3월 27일
I have difficulty in understanding your question try "continue" instead of "break".
BdS
BdS 2019년 3월 27일
If I add "break" to my code. Then matlab jumps to the loop interation d=2:nDates. Thats good. But it is only the half solution. What I am looking for: After jumping back to d=2:nDates I want that i=2:nRebIndi continues to the next Itereation.
In other words:
the first loop iteration for nDates is 2 (as it begins by 2) and for the nRebIndi is 2 as well. After those first Interations (if I insert break), matlab jumps to the next iteration. Which is nDates 3 BUT nRebIndi iteration stays frozen at 2 (because of brerak) instead also showing 3

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

답변 (1개)

Stephan
Stephan 2019년 3월 27일
  댓글 수: 1
BdS
BdS 2019년 3월 27일
Thanks for your answer.
The thing is that with "break" matlab jumps to d=2:nDates which is what I want. However, the loop i=2:nRebIndi stays frozen/terminates. And I want this loop (Iteration) to continue after getting to d=2:nDates.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by