Wednesday, July 30, 2008

advanced way to export figures using hgexport with matlab

i will explain how to export figures to a file using hgexport with matlab.
here is how:
first you need to create the figure:

h.figure = figure
position = get(gcf,'Position');
'PaperPositionMode', 'auto', ...
'Units','in','Position',[position(1:2) 6 2.5 ],...
'PaperPosition',[0.25 0.25 6 2.5])

then, plot the figure. use all the commands you like, like plot, stairs and subplot...
at the end, export the figure using hgexport:

myStyle = hgexport('factorystyle');
myStyle.Format = 'png';
myStyle.Width = 6;
myStyle.Height = 2.5;
myStyle.Resolution = 300;
myStyle.Units = 'inch';
myStyle.FixedFontSize = 12;

with Width and Height you can control the size of the file in inch (units).


Anonymous said...

super, danke otmezger,
genau das brauchte ich

Anonymous said...

Awesome... Thank you!

Anonymous said...

Great code! Thank you!
I have a further question:
I use export_fig to finally do the exportation.
Therefore, I want to use hgexport ONLY to setup the figure style, but NOT to use the hgexport to do the exportation.
Is there a way using hgexport or other codes to only set the figure style but not do the exportation.

Thank you!

sarah lee said...

A people without the knowledge of their past history, origin and culture is like a tree without roots. See the link below for more info.