Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pymatbridge/matlab/util/make_figs.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
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);
% 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 = ['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
close(h);
fig_files{fig} = [filename '.png'];
fig_files{fig} = filename;
end

end %function