Closed corwin365 closed 4 years ago
This is a problem with the builtin Matlab function for writing PNG files, and specifically the compiled MEX function pnwritec
that is located in %matlabroot%/toolbox/matlab/imagesci/private/ .
Because of the randomness of the problem, my hunch is that this MEX function may still be in use when you're trying to re-use it in a follow-on invocation. Try to add a short pause(0.5)
between your calls to export_fig
and see if this helps.
Thanks for the reply, will give it a go!
I updated my export_fig to the most recent version a couple of weeks days ago - my previous version was about 2 years old, but I'm not sure of the exact number. Since the update, I am getting sporadic crash-errors when generating pngs, with the following error message:
export_fig error. Please ensure:
If the problem persists, then please report a new issue.
Error using pngwritec PNG library failed: Could not open file.. Error in writepng (line 280) pngwritec(data, map, filename, colortype, bitdepth, ... Error in imwrite (line 559) feval(fmt_s.write, data, map, filename, paramPairs{:}); Error in export_fig (line 732) imwrite(A, [options.name '.png'], 'ResolutionUnit','meter', 'XResolution',res, 'YResolution',res, format_options{:});
The error is random and hard to reproduce- if I immediately export the same figure again it works, and if I rerun the same script with identical settings it work. Sorry I can't be more helpful. I would guess this is happening roughly 5% of the time I call export_fig. I usually run with a4 and m2 if that is a factor, i.e. commands of the form export_fig(FileName,'-png','-m2','-a4').