From 2f0ba41918acfeca14ae9fdf8c457f3d009dc1bf Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 7 Feb 2015 13:03:10 -0600 Subject: [PATCH 1/2] Add ability to set image format and resolution, with saner default --- pymatbridge/matlab/util/make_figs.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pymatbridge/matlab/util/make_figs.m b/pymatbridge/matlab/util/make_figs.m index 239110e..fcfa605 100644 --- a/pymatbridge/matlab/util/make_figs.m +++ b/pymatbridge/matlab/util/make_figs.m @@ -1,21 +1,30 @@ -function fig_files = make_figs(figdir) +function fig_files = make_figs(figdir, fmt, res) % Get all the figures that are currently open (presumably from a cell % that was just executed): figHandles = get(0, 'children'); fig_files = {}; +if (nargin < 2) + fmt = 'png' +end +if (nargin < 3) + res = 96 +end + for fig=1:length(figHandles) h = figHandles(fig); + res_fmt = sprintf('-r%d', res); + driver = sprintf('-d%s', fmt) % We will put all of these in the temp dir with an identifying root, so % that we can grab all of them into the cell (and they will be deleted % immediately after being rendered). - filename = fullfile(figdir, ['MatlabFig', sprintf('%03d', fig)]); - saveas(h, [filename, '.png']); + filename = fullfile(figdir, ['MatlabFig', sprintf('%03d.%s', fig, fmt)]); + print(h, filename, driver, res_fmt); % Once you've saved it, close it, so it doesn't get dragged into the % scope of other cells close(h); - fig_files{fig} = [filename '.png']; + fig_files{fig} = filename; end end %function From 0868cb69eb29033e725c369d811c4b587a0e20e1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 7 Feb 2015 16:58:57 -0600 Subject: [PATCH 2/2] Clean up fig_files --- pymatbridge/matlab/util/make_figs.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pymatbridge/matlab/util/make_figs.m b/pymatbridge/matlab/util/make_figs.m index fcfa605..e794e7d 100644 --- a/pymatbridge/matlab/util/make_figs.m +++ b/pymatbridge/matlab/util/make_figs.m @@ -14,12 +14,13 @@ for fig=1:length(figHandles) h = figHandles(fig); - res_fmt = sprintf('-r%d', res); - driver = sprintf('-d%s', fmt) % We will put all of these in the temp dir with an identifying root, so % that we can grab all of them into the cell (and they will be deleted % immediately after being rendered). - filename = fullfile(figdir, ['MatlabFig', sprintf('%03d.%s', fig, fmt)]); + filename = ['MatlabFig', sprintf('%03d.%s', fig, fmt)]; + filename = fullfile(figdir, filename); + res_fmt = sprintf('-r%d', res); + driver = sprintf('-d%s', fmt); print(h, filename, driver, res_fmt); % Once you've saved it, close it, so it doesn't get dragged into the % scope of other cells