Using Print command to save pdf of figure to a different directory
Show older comments
Hi,
I have struggled to create a pdf of a figure and put it in a Latex directory for inclusion in an academic paper. I can create the pdf with no difficulty to the present matlab working directory which is C:\Thomas Jacobs\Dropbox\Matlab:
...
h=gcf;
set(h,'Position',[0 0 1200 800]);
set(h,'PaperOrientation','landscape');
set(h,'PaperPositionMode','auto');
print(gcf,'-dpdf','SVGL_2Yr_Annual.pdf');
however, when I try to change the target directory to a Latex subfolder:
...
h=gcf;
set(h,'Position',[0 0 1200 800]);
set(h,'PaperOrientation','landscape');
set(h,'PaperPositionMode','auto');
print(gcf,'-dpdf','C:\Thomas Jacobs\Dropbox\Latex\Research\FHLB Advances\SVGL_2Yr_Annual.pdf');
I get:
>> FHLB_SVGL2_Analysis Error using name (line 102) Cannot create output file 'C:\Thomas Jacobs\Dropbox\Latex\Research\FHLB Advances\SVGL_2Yr_Annual.pdf'
Error in print (line 210) pj = name( pj );
Error in FHLB_SVGL2_Analysis (line 70) print(gcf,'-dpdf','C:\Thomas Jacobs\Dropbox\Latex\Research\FHLB Advances\SVGL_2Yr_Annual.pdf');
This target directory is not in my matlab path and the delay between the creation of the figure on my screen and the program completion makes me wonder if this is some sort of write permission issue. While I have seen many combinations of using other commands like saveas, sprintf, etc., I have not found an exact analogy for my issue on the forum and would appreciate it if one of you could share some further troubleshooting steps for me. Thanks.
Tom
3 Comments
Salaheddin Hosseinzadeh
on 21 Mar 2014
Is it a write permission problem? You're suspecting if this is the case! Did you check if you or preferably everyone has full control permission?
Thomas Jacobs
on 22 Mar 2014
Mehdi Zomorodian
on 14 Sep 2017
Dear Thomas,
As I understood, the print function cannot create a new directory, so if you try to save your file in a new one, you will face this problem. So, a quick solution is to create the directory manually or by coding before trying to use print function.
Accepted Answer
More Answers (1)
Joseph Cheng
on 21 Mar 2014
can you use
...
h=gcf;
set(h,'Position',[0 0 1200 800]);
set(h,'PaperOrientation','landscape');
set(h,'PaperPositionMode','auto');
print(gcf,'-dpdf','SVGL_2Yr_Annual.pdf');
movefile('SVGL_2Yr_Annual.pdf','C:\Thomas Jacobs\Dropbox\Latex\Research\FHLB Advances\SVGL_2Yr_Annual.pdf')
If that's the case it might not be a permissions issue.
2 Comments
Salaheddin Hosseinzadeh
on 21 Mar 2014
I don't like this, even if it works!
Joseph Cheng
on 21 Mar 2014
I don't like it either! I guess I could have suggested trying to fid = fopen a random temp file? But it was something that would test out writing to the directory and I cannot see anything wrong with his command.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!