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