Error when plotting in parfor loop
23 ビュー (過去 30 日間)
古いコメントを表示
David Perlmutter
2018 年 12 月 19 日
コメント済み: Walter Roberson
2021 年 9 月 3 日
I'd like to plot inside a parfor loop, but am getting an error I don't understand.
parfor i=1:10
figure;
end
Cannot set WindowStyle to 'docked' when MATLAB is
started with no display or when the -noFigureWindows
option is specified.
I have changed my default window style but got the same error
set(0,'defaultfigurewindowstyle','normal')
set(0,'defaultfigurewindowstyle','docked')
1 件のコメント
Mark Sherstan
2018 年 12 月 19 日
Are you running any other code before the loop? What version of MATLAB and parrallel toolbox are your using?
採用された回答
David Perlmutter
2018 年 12 月 19 日
1 件のコメント
Walter Roberson
2018 年 12 月 19 日
It does sound like you have set(0,'defaultfigurewindowstyle','docked') in effect. Check for a startup.m that might be setting it.
その他の回答 (5 件)
Walter Roberson
2018 年 12 月 19 日
It is never possible to plot to the display inside any parallel construct. The workers are in separate processes that do not have access to the graphics subsystem.
You would need to either:
- Calculate all of the data in the parfor and then do the plotting after the parfor; or
- Use parallel.pool.DataQueue or parallel.pool.PollableDataQueue and send() data back to the client to do the plotting such as by using foreach
0 件のコメント
Mark Sherstan
2018 年 12 月 19 日
編集済み: Mark Sherstan
2018 年 12 月 19 日
To save a figure in a parfor loop you must do the following as found here. Otherwise save the data and plot after as mentioned by Walter.
parfor i=1:5
figure(i)
plot(rand(i*10,1));
saveas(gcf,['temp' num2str(i) '.jpg']);
end
Try the code above and let us know if the error continues.
0 件のコメント
David Perlmutter
2018 年 12 月 19 日
1 件のコメント
Walter Roberson
2018 年 12 月 19 日
Note that the plots are not just "invisible": they are in a different process. You would need to save them or else find a way to bring back the figures.
David Perlmutter
2018 年 12 月 20 日
2 件のコメント
Jackson Jewett
2021 年 9 月 3 日
Could you clarify this? Are you able to display plots within a forloop? Could you advise what you commented out in order to see these results? Thank you!
Walter Roberson
2021 年 9 月 3 日
David was saving the plots inside the loop; see https://www.mathworks.com/matlabcentral/answers/436570-error-when-plotting-in-parfor-loop#answer_353192
You can save plots inside of parfor; you just cannot display them to the user from inside of the parfor.
参考
カテゴリ
Help Center および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!