Parfor with two loop variable

2 ビュー (過去 30 日間)
Hongbo Zhao
Hongbo Zhao 2018 年 5 月 14 日
回答済み: Sid Jhaveri 2018 年 5 月 17 日
I would like to use the following code to run certain simulations labeled by “cases” number in parallel and also plot the result in consecutive subplots.
cases = [2,5,8];
parfor casenum = cases
result(casenum) = ...;
subplot(1,3,?)
end
In the example above, the question mark should be 1, 2, 3 for the three cases.
I know the following code doesn’t work because “result” is a sliced variable. And “result(casenum(i))” is not allowed.
cases = [2,5,8];
parfor i=1:length(cases)
result(cases(i)) = ...;
subplot(1,3,i)
end
Is there any way to work around this without having to resort to storing results with indexes 1 through 3?

採用された回答

Sid Jhaveri
Sid Jhaveri 2018 年 5 月 17 日
Hi,
You might want to try doing something like the code given below:
cases = [2,3,4];
result = zeros(1,4);
parfor i=cases
index = find(cases == i);
result(i) = i;
subplot(1,3,index)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by