Use parfor to save figure but it tried to display and got hanged

5 ビュー (過去 30 日間)
Dao Nguyen
Dao Nguyen 2023 年 2 月 8 日
コメント済み: Lars 2025 年 3 月 10 日
Dear all,
I am trying to save several figures at once using parfor. The code works alright in MATLAB 2019b, but after the upgrade to 2022b, the code got stucked at object.displayOutput() in remoteparfoor. Does anyone have any idea? Thanks a lot!
I tried to set the figure visibility to 'off' (set 'visibility' to 'off', and set(0, 'DefaultFigureVisible', 'off')), but they both didn't work.
I tried to close the figure after saving (somehow the figures were saved first, then it got stucked at object.displayOutput)
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
parfor iFig = 1:length(FigList)
FigHandle = FigList(iFig);
figureFile= [folderPath FigHandle.Name '.png'];
saveas(FigHandle,figureFile);
end
close all;
If paused:
function [tags, results] = getCompleteIntervals(obj, numIntervals)
q = obj.IntervalCompleteQueue;
timeUnitSeconds = iTimeUnitSeconds();
tags = nan(numIntervals, 1);
results = cell(numIntervals, 2);
for i = 1:numIntervals
r = [];
err = [];
while isempty(r)
assert(obj.NumIntervalsInController > 0, ...
'Internal error in PARFOR - no intervals to retrieve.');
r = q.poll(1, timeUnitSeconds);
obj.displayOutput(); % <======= pause here

回答 (1 件)

Raghav
Raghav 2023 年 4 月 5 日
Hi,
Based on your question, I understand that you are facing difficulty using saveas function in parfor loop.
After going through the code, everything looks good and should work fine.. However, there might be some issue with the parfor loop. Here are some suggestions you can try to see if they solve the issue:
  1. Try running the code without the parfor loop to see if it works fine.
  2. If running the code without parfor works fine, then try running the code with a regular for loop to see if it works fine.
  3. Try running the code on a different MATLAB version to see if the issue persists.
  4. You can also try using the matlab.io.export_fig package to save figures. It is a very useful tool for exporting figures in different file formats, including png.
  5. If the issue still persists, please reach out to MathWorks technical support for assistance.
Hope it helps!
Thanks,
Raghav Bansal
  2 件のコメント
Dao Nguyen
Dao Nguyen 2023 年 7 月 31 日
Thank you a lot for your help. It seems there was an issue with the outdated driver for parallel works in my computer. After the update, it works normally.
Best,
Dao
Lars
Lars 2025 年 3 月 10 日
Hi
It seems like I am having the same issue. Which drivers did you update?
Best regards
Lars

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

カテゴリ

Help Center および File ExchangeCode Execution についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by