Is there a way of programmatically applying saved Export Styles post R2024b?

14 次查看(过去 30 天)
This was possible, ≤ R2024b, via
hgexport('readstyle',<stylename>)
This function was removed for R2025a, and I seem unable to find an equivalent functionlaity with repsect to export-styles.
I do note that, while the above syntax works ≤ R2024b, I'm now unable to find a reference to the 'readstyle' option anywhere, including in the docs for hgexport itself.

回答(2 个)

Leia
Leia 2025-7-23
Hi @Amos, depending on your use case, you may want to use exportgraphics, copygraphics, or exportapp as an alternative to hegexport. See the Version History for hgexport for more information on these alternate functions available to export the contents of the figure.
If you are interested in changing figure properties, like font size or line width, the recommended workflow as of R2025a is to set figure properties, either interactively or programmatically before exporting.
For example, if you are interested in changing the font size, you can use the fontsize function to update the font size before exporting. For changing properties such as the line width, you can use findobj and set to change the values before exporting:
plot(rand(5))
p = findobj(gcf,'Type','line');
set(p,'LineWidth',3);
Also available in 25a, the uiexportdlg can be used to export figures, and the options for the dialog are automatically saved and restored, however it is not possible to save and load different export styles. The uiexportdlg can be accessed from the command line or selecting Save As > Export To... on the figure.
We understand that this change to remove hgexport may impact your workflows, and would love to hear more regarding your typical workflows. Could you please share which style sheet fields you consider important to set in your workflow?

Ruchika Parag
Ruchika Parag 2025-7-23
Hi @Amos, in MATLAB R2025a, the hgexport('readstyle', ...) functionality has been removed, and it's no longer documented or supported. Previously, this allowed users to read and apply export style files (.txt) saved via the Export Setup dialog. As of R2025a, that workflow is deprecated.
To achieve similar functionality in modern MATLAB versions, consider the following alternatives:
  1. Use exportgraphics: This function provides a programmatic and consistent way to export figures with options like resolution, format, background color, and more:
exportgraphics(gcf, 'output.pdf', 'Resolution', 300, 'BackgroundColor', 'white');
2. This replaces most use cases for hgexport, especially when exporting figures for publication or documentation.
  • Manual Style Setup (GUI): If you were using styles from the Export Setup dialog, those can still be configured manually through:
File > Export Setup
  • However, there’s no longer a programmatic way to read those .txt styles in R2025a.
3. Recreating Styles in Code: You can define reusable export configurations using structs or function wrappers. For example:
opts = struct('ContentType', 'vector', ...
'BackgroundColor', 'white', ...
'Resolution', 300);
exportgraphics(gcf, 'figure.pdf', opts);
  • This allows you to script your export process consistently without relying on style files.
4. Multipage PDF Support: As of R2025a, exportgraphics also supports appending to PDF files using the 'Append' option:
exportgraphics(gcf, 'report.pdf', 'Append', true);
If you relied on hgexport styles for automation or consistency, the recommended path forward is to replicate those settings manually in code using exportgraphics. Unfortunately, there is no direct replacement for hgexport('readstyle', ...) at this time. Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by