Jump to next loop (alternative goto)

8 Ansichten (letzte 30 Tage)
BdS
BdS am 27 Mär. 2019
Kommentiert: BdS am 27 Mär. 2019
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 Kommentare
madhan ravi
madhan ravi am 27 Mär. 2019
I have difficulty in understanding your question try "continue" instead of "break".
BdS
BdS am 27 Mär. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephan
Stephan am 27 Mär. 2019
  1 Kommentar
BdS
BdS am 27 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by