Export Figure using Print
Show older comments
I (want to) use the print command for exporting a Figure (here: f1) using the following code:
print -f1 -dpng -r600 \\folder\subfolder1\filename
It works quiete good, however, I would like to manipulate the file location, for example, a loop where the file ist exported to subfolder2, subfolder3 and so on. It seems that everything behind print is a string. Unfortunately, "normal" string manipulation like the following is not working here,
for i=1:5 print .... '\\folder\subfolder',num2str(i),'\filename' end
Is there any option to overcome this? P.S. I do not want to swap from print to another export command, because it took a lot of time to make all the figures look good as tehy do now (with the rigth font and fontsize,...)
Appreciate help.
Answers (2)
This might help:
You could use the same to write sequence of files
Instead of reading files, you have to write sequence of directories ..
I'm on a mac and so this works for windows you might want to change the / to \ to traverse the directory
for ii=1:3
savedir=strcat('new',num2str(ii));
mkdir(savedir);
newname=[savedir '/' 'image.jpg'];
h=figure;
plot(1:4*ii)
saveas(h,newname);
end
2 Comments
Jan
on 20 Sep 2012
Matlab's makedir() command might be more convenient than calling a system function.
ii = 1;
print('-f1', '-dpng', '-r600', sprintf('\folder\subfolder%d\filename', ii));
The functional form of commands is safer, because the interpretation of the abbreviated form without parenthesis depends on the Matlab version. Example:
Ok in 2009a:
fullfile * *
Fails in 2009a, but works in older versions:
fullfile * p
Fails in 2009a:
strcat * 2 % Error using STRCAT: not enough input arguments
strcat * _ % Error: the input character is not valid
But this works:
strcat 1 * 2 % '1*2'
strcat a _ % 'a_'
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!