For loop with 2 variables

4 ビュー (過去 30 日間)
B.E.
B.E. 2021 年 11 月 19 日
編集済み: B.E. 2021 年 11 月 23 日
Hi,
Hi, I'm looking for an idea on how to iterate all possible combinations for the couple using the for loop, to apply the parfor loop in my code.
for example
without using the for loop twice:
for i =1:N
parfor j =1:N
.......
end
end
  3 件のコメント
B.E.
B.E. 2021 年 11 月 19 日
編集済み: B.E. 2021 年 11 月 19 日
%% The Code used is:
Y_1 =zeros(N,numel(alpha),numel(beta));
Y_2 =zeros(N,numel(alpha),numel(beta));
for i = 1:numel(alpha)
parfor j =1:numel(beta)
[Y_1(:,i,j),Y_2(:,i,j)] = My_Fun(alpha(i),beta(j),......)
end
end
Matt J
Matt J 2021 年 11 月 20 日
編集済み: Matt J 2021 年 11 月 20 日
That doesn't really give us any information. All of the details of your computation are hidden inside My_Fun().

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

採用された回答

Matt J
Matt J 2021 年 11 月 19 日
編集済み: Matt J 2021 年 11 月 19 日
parfor k =1:N^2
[i,j]=ind2sub([N,N],k);
....
end
  4 件のコメント
B.E.
B.E. 2021 年 11 月 20 日
The problem is solved.
Thank you so much Matt J
B.E.
B.E. 2021 年 11 月 23 日
編集済み: B.E. 2021 年 11 月 23 日
Hi Matt J,
My code is executed normally without the parfor command i.e with the for command.
If I reduce the numbre of cores to 4, my code will run normally with the parfor command.
Can you help me this is urgent.
Thank you again for your help.

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

その他の回答 (0 件)

カテゴリ

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