exportgraphics with 'patch' crashing Matlab 2024a

20 visualizaciones (últimos 30 días)
DANILO ALARCON
DANILO ALARCON el 6 de Jun. de 2024
Comentada: Avraham Shalev el 21 de Ag. de 2024
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 comentario
Adam Danz
Adam Danz el 6 de Jun. de 2024
Editada: Adam Danz el 6 de Jun. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Matlab Pro
Matlab Pro el 6 de Jun. de 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 comentarios
DANILO ALARCON
DANILO ALARCON el 6 de Jun. de 2024
Editada: DANILO ALARCON el 6 de Jun. de 2024
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 el 21 de Ag. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by