How can I save graphics as pdf?

Hello everyone,
I'd like to save graphics as pdf and I tried in this way, but I can't get what I have to write instead of "myfigure".
Thank you!
saveas(gcf,'myfigure.pdf')

 Accepted Answer

Dave B
Dave B on 19 Nov 2021
Edited: Dave B on 19 Nov 2021
What you typed should work, it should save the current figure (gcf) as myfigure.pdf to the current directory.
I'd recommend using exportgraphics instead of saveas if you're using 2020a or later. exportgraphics is more modern and is graphics specific.
If you're not finding your pdf, is it possible you're not looking in the correct directory? The directory is shown near the top of the MATLAB desktop, but you can also see it by calling the function pwd.
If you didn't want to save the 'current figure' replace gcf with the figure number. Unfortunately this is slightly more complicated with exportgraphics
saveas(3,'foo.pdf'); % exports figure 3
exportgraphics(figure(3),'foo.pdf'); % exports figure 3

7 Comments

Pul
Pul on 24 Nov 2021
Edited: Pul on 24 Nov 2021
I can see just a blank page.
Can you save it as a .fig file (e.g. with savefig) and then upload that file here?
Yes, here they are.
It looks to me like Graphic.fig is totally empty - are you sure you're pointing the command at the correct figure?
Yes, it's empty for me too.
I wrote this:
savefig('Graphic');
saveas(gcf,'myfigure.pdf')
@Pul - the current figure is empty, if you're trying to save a specific figure please use the syntax shown in my snippet above.
Okay, thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Asked:

Pul
on 19 Nov 2021

Commented:

Pul
on 25 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!