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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by