exportgraphics with 'patch' crashing Matlab 2024a

조회 수: 8 (최근 30일)
DANILO ALARCON
DANILO ALARCON 2024년 6월 6일
댓글: Avraham Shalev 2024년 8월 21일
I've recently changed from Matlab 2022a to 2024a and some plotting and saving scripts are crashing Matlab (the ones that don't crash take much more time to save).
I am plotting patches and saving them as vector images ('eps')
In the script below, there is one example. This exampe don't crash Matlab 2024a, but the exportgraphics function time jumps from 12 seconds (2022a) to 16 minutes (2024a). EPS file size is around 20mb.
I am aware that the plot may seem to big to be vectored (lots of points), but a big change has happened between 2022 and 2024 to raise this issue
figure
L1_color = [0.7 1 0.8];
L2_color = [1 1 0.6];
L3_color = [1 0.6 0.6];
t = 0:0.001:95;
x = 0.5*sin(t)+1;
patch([t , t(end), t(1), t(1)], 3-[x , 0, 0, x(1)], L1_color)
patch([t , t(end), t(1), t(1)], 3-[x , 0, 0, x(1)]*.5, L2_color)
patch([t , t(end), t(1), t(1)], 3-[x , 0, 0, x(1)]*0.25, L3_color)
patch([t , t(end), t(1), t(1)], [x , 0, 0, x(1)], L1_color)
patch([t , t(end), t(1), t(1)], [x , 0, 0, x(1)]*.5, L2_color)
patch([t , t(end), t(1), t(1)], [x , 0, 0, x(1)]*0.25, L3_color)
tic
exportgraphics(gcf,'Test001.eps','Resolution',150,'ContentType','vector')
toc
  댓글 수: 1
Adam Danz
Adam Danz 2024년 6월 6일
편집: Adam Danz 2024년 6월 6일
@DANILO ALARCON, it would be helpful to contact tech support (> Produce Usage > Errors or Performance Issues) and include instructions how to reproduce the problem. Also include whether or not you are using the beta release in R2024a (the beta release would have required you to download it from the File Exchange and turn it on).
Feel free to include the URL of this thread.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matlab Pro
Matlab Pro 2024년 6월 6일
When I made 't' smaller (t = 0:0.001:2;) - it ran smoothly,
When I enlarge it (t = 0:0.001:10;) and run - I get the next warning
Warning: Vectorized content might take a long time to create, or it might contain unexpected results. Set 'ContentType' to 'image' for better performance.
So - Going after that recommendation: going back to the maximal 't' and changing 'ContentType' to 'image' - it finished in ~4 seconds
t = 0:0.001:95;
...
exportgraphics(gcf,'Test001.eps','Resolution',150,'ContentType','image')
  댓글 수: 2
DANILO ALARCON
DANILO ALARCON 2024년 6월 6일
편집: DANILO ALARCON 2024년 6월 6일
Yes, these solutions work.
What I did here was to change the discretization of the "t" vector to 0:0.1:95 as I wanted the full array and a vectorized image to be zoomed when I use it in a Latex file (just to remember, my image is not the one I've sent, that is just a simpler example that reproduce the error)
However, what raised my concern is the big change between the two Matlab versions (and changed for the worse :/)
Avraham Shalev
Avraham Shalev 2024년 8월 21일
You can convert the warning to an error and use try-catch mechanism to export as an image instead:
warning('error', 'MATLAB:print:ContentTypeImageSuggested')
try
exportgraphics(gcf,'Test001.eps','Resolution',150,'ContentType','vector')
catch ME
if (strcmp(ME.identifier,'MATLAB:print:ContentTypeImageSuggested'))
exportgraphics(gcf,'Test001.eps','Resolution',150,'ContentType','image')
else
rethrow(ME)
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by