Use parfor to save figure but it tried to display and got hanged
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
Risposte (1)
Raghav
il 5 Apr 2023
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:
- Try running the code without the parfor loop to see if it works fine.
- If running the code without parfor works fine, then try running the code with a regular for loop to see if it works fine.
- Try running the code on a different MATLAB version to see if the issue persists.
- 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.
- If the issue still persists, please reach out to MathWorks technical support for assistance.
Hope it helps!
Thanks,
Raghav Bansal
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!