exportgraphics with 'patch' crashing Matlab 2024a
20 ビュー (過去 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
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
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 件のコメント
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 Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!