フィルターのクリア

Code that makes matlab jumping loops without fininishing the remaining iterations.

3 ビュー (過去 30 日間)
BdS
BdS 2019 年 4 月 3 日
コメント済み: BdS 2019 年 4 月 10 日
Hi,
I have got the following 2 loops:
for d=1:nDates %loop over rebdates
for r=1:nRebDates
ind=ismember(PortMembers,rawPortData{d}.PORTFOLIO_MPOSITION{1}(:,1));
PortPositions(d,ind)=cell2mat(rawPortData{r}.PORTFOLIO_MPOSITION{1}(:,2));
end
end
I would like that everytime when one iteration from loop r=r:nRebDates is concluded matlab jumps directly to the first loop d=1:nDates instead of first complete all iterations in loop r=r:nRebDates.
(break does not work as I do want that iteration r=r:nRebDates continues but only after matlab goes through d=1:nDates for a 2nd,3th, 4th... time)
(continue does not work as well as I do want a second iteration of r=r:nRebDates but only after matlab goes to the first loop d=1:nDates)
--> actually is as when I would tell Matlab: after the code line PortPositions(d,ind)=cell2mat(rawPortData{r}.PORTFOLIO_MPOSITION{1}(:,2)); go to d=1:nDates
Do you have any hints?
Thank you in advance.

回答 (2 件)

Bob Thompson
Bob Thompson 2019 年 4 月 3 日
I'm not entirely sure I understand what you're asking for, but it seems like you want to run all iterations of the d loop with the first r value before proceeding to the second r value.
If this is the case, then why don't you just reverse the order of the two loops?
for r=1:nRebDates
for d=1:nDates %loop over rebdates
ind=ismember(PortMembers,rawPortData{d}.PORTFOLIO_MPOSITION{1}(:,1));
PortPositions(d,ind)=cell2mat(rawPortData{r}.PORTFOLIO_MPOSITION{1}(:,2));
end
end
  2 件のコメント
Bob Thompson
Bob Thompson 2019 年 4 月 9 日
Per your other comments, it sounds like you're just trying to loop through both sets of values at once. To do that you can just use one loop.
r = 1:nRebDates;
d = 1:nDates;
for i = 1:length(r);
ind=ismember(PortMembers,rawPortData{d(i)}.PORTFOLIO_MPOSITION{1}(:,1));
PortPositions(d(i),ind)=cell2mat(rawPortData{r(i)}.PORTFOLIO_MPOSITION{1}(:,2));
end
This will run into problems if your r and d values are of different sizes, but otherwise it should work fine.
BdS
BdS 2019 年 4 月 10 日
Thank you for your answert. Yes, r and d values are of different sizes.

サインインしてコメントする。


BdS
BdS 2019 年 4 月 4 日
Thank you for your answer. I wasn't clear.
Here is the procedure I woul like:
1) First iteration r
2) First iteration d, excecute code (ind=...; PortPositions...)
3) JUMP to SECOND iteration r
4) go on to SECOND iteration d, excecute code...
5) JUMP to THIRD iteration r
6) go on to THIRD iteration d
...(and so on)
I hope that I was clear this time. I think that these kind of questions arrive a lot... specially for programmers who write codes in other programs . (for which go to command exists)
  1 件のコメント
BdS
BdS 2019 年 4 月 8 日
In the meantime I was able to solve this question...
However, I would like that someone from matlab takes this question and gives me/us/=matlab users some powerful solutions as I think that this kind of questions arise by other users.
thanks in advance.

サインインしてコメントする。

カテゴリ

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