Hi,
i was wondering if there is a posibility to export a figure directly from the commandline using matlab using a predefined style.
well... there is.
i have made a function (inspired on this link) called fig2png where you can do it (at the end of this post). To call the function, use this:
fig2png(gcf,'fig1.png','style_FfE_ppt')
function fig2png(figname,filename,sname)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tmezger@ffe.de
% 08.11.2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%this function exports the figure figname to a file filename, using the
%style sname
% the style hast to be in your matlab home!!!
%% check if figure is docked
if strcmpi(get(figname,'WindowStyle'),'docked')
undock = 1;
else
undock = 0;
end
%% set style
s=hgexport('readstyle',sname);
%% undock
if undock == 1
disp(['undocking figure ' figname])
set(figname,'WindowStyle','normal')
end
%% export to filename
hgexport(figure(1),filename,s)
disp('file written')
%% export to clipboard
hgexport(figure(1),'-clipboard',s)
disp('exported to clipboard')
%% dock aggain if it was docked
if undock == 1
set(figname,'WindowStyle','docked')
disp(['docking figure ' figname ' aggain'])
end
No comments:
Post a Comment