exportgraphics in MATLAB online only gives empty PNG-file.

조회 수: 12 (최근 30일)
Constantin Tabor
Constantin Tabor 2022년 8월 24일
답변: Richard Quist 2022년 8월 26일
Hi everybody,
I really cannot figure out what I am doing wrong here. When I run this code in a .m-file on MATLAB online (R2022a, Update 4), I only get an empty png file (0KB). It used to work well.. Also manually saving the file to the online folder gives a 0KB PNG-file.
Must be something about the gca, I guess.
t= [0 60 163 204 282 361 415 460 560 761];
U = [9.05 8.00 6.44 6.00 5.18 4.41 4.00 3.61 2.98 2.00];
%title and stuff
title('Grafic to export');
ylabel('I don''t know Y ');
ax = gca;
I appreciate your help and thanks a lot.
EDIT: It works when I run exportgraphics on the command line. But why wont it export when it runs in the .m-file?

답변 (1개)

Richard Quist
Richard Quist 2022년 8월 26일
Your original code looks like it should work - I suggest contacting support for help.
In the meantime, you could try the following 2 potential work arounds
Workaround #1: add a call to drawnow before the call to exportgraphics. If it's a timing issue where the plot wasn't drawn when exportgraphics started to process it then this may help.
% ...
% ^^^ your original code to create the plot ^^^
% NEW: call drawnow to give the plot a chance to render
% your export call
Workaround #2: Rather than use gca, try creating the axes separately and then using that axes handle when plotting your data, adding the title, etc, and in the call to exportgraphics.
ax = axes;
t= [0 60 163 204 282 361 415 460 560 761];
U = [9.05 8.00 6.44 6.00 5.18 4.41 4.00 3.61 2.98 2.00];
plot(ax, t,U); % <<= use ax here
%title and stuff
title(ax, 'Grafic to export'); % <<= use ax here
xlabel(ax, 'X-factor'); % <<= use ax here
ylabel(ax, 'I don''t know Y '); % <<= use ax here
%ax = gca; % <<= Don't use gca here


Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by