exportgraphics with 'patch' crashing Matlab 2024a

33 次查看(过去 30 天)
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,16:49
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 中查找有关 Convert Image Type 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by