exportgraphics with 'patch' crashing Matlab 2024a
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Adam Danz
am 6 Jun. 2024
Bearbeitet: Adam Danz
am 6 Jun. 2024
@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.
Antworten (1)
Matlab Pro
am 6 Jun. 2024
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 Kommentare
Avraham Shalev
am 21 Aug. 2024
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
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!