How to use print in a parfor
Show older comments
Whenever I am using print inside a parfor, I get some all black images. How do I fix this?
Here is a snippet of code and I attached the variables figs and output_files (I had to make them way smaller to upload).
Thanks!!
load('variables.mat')
% output resolution and format
outputDPI = '-r900';
outputFmt = '-dpng';
parfor f = 1:numel(figs)
figure1 = figs{f};
output_file = output_files{f};
if ~isempty(figure1)
opengl software
set(groot, 'DefaultFigureRenderer', 'painters');
print(figure1, output_file, outputFmt, outputDPI);
close(figure1);
end %if ~isempty(figure1)
end %for f = 1:numel(figs)
4 Comments
Raymond Norris
on 23 Aug 2021
I can't reproduce the issue, but I don't quite follow the statement I get some all black images. Are you saying that some of the images are all black?
I don't think it'll matter, but you mention that you had to make the figs and output files much smaller. Have you tried running the parfor with the files you uploaded and see the issue? I doubt the larger files would be an issue.
Another thought is to remove opengl. Doubt it will cause the issue, but worth pulling things out to troubleshoot.
meghannmarie
on 23 Aug 2021
Alvaro
on 19 Jan 2023
I am getting this error when using parfor
Error using print
Functionality not supported with figures created with the uifigure function.
and this error when using for
Error using checkArgsForHandleToPrint
Handle input argument contains nonhandle values.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 101)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
In any case, would just running this in serial work out? Or are you trying to speed up the rendering?
Walter Roberson
on 19 Jan 2023
WIth your actual data file, please execute
cellfun(@(C) isprop(C,'isUIFigure'), figs)
and see if some of them show up as 1 . Any entries that show up as 1 correspond to uifigures -- uifigure have that property but traditional figure do not have that property.
Answers (0)
Categories
Find more on Develop Apps Programmatically in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!