Skip to content

Instantly share code, notes, and snippets.

@ha7ilm
Created June 29, 2024 16:43
Show Gist options
  • Save ha7ilm/d101868dc6cb0d558bea137b44d1ff63 to your computer and use it in GitHub Desktop.
Save ha7ilm/d101868dc6cb0d558bea137b44d1ff63 to your computer and use it in GitHub Desktop.
Saving a figure to PDF in MATLAB for a paper
% Set figure size and save
set(gcf, 'Position', [1 1 900 250]);
fig = gcf;
fig.PaperUnits = 'points';
fig.PaperPosition = [0 0 fig.Position(3) fig.Position(4)];
fig.PaperSize = [fig.Position(3) fig.Position(4)];
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
saveas(fig, ['something.pdf'], 'pdf');

Optionally, to save it based on the currently running script's name:

saveas(fig, [mfilename('fullpath'), '.pdf'], 'pdf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment