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 CenterFile Exchange에서 Code Execution에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by