Export Figure using Print

7 次查看(过去 30 天)
Timo
Timo 2012-9-20
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.

回答(2 个)

Thomas
Thomas 2012-9-20
编辑:Thomas 2012-9-20
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 个评论
Jan
Jan 2012-9-20
Matlab's makedir() command might be more convenient than calling a system function.
Thomas
Thomas 2012-9-20
编辑:Thomas 2012-9-20
true, Thanks Jan, I forgot about it.. Edited accordingly

请先登录,再进行评论。


Jan
Jan 2012-9-20
编辑:Jan 2012-9-20
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_'
  2 个评论
Timo
Timo 2012-9-20
Thanks for the answer. It looks interesting but it leads to the error: Error using name (line 104) Cannot create output file 'c:\older.png'
Error in print (line 206)
pj = name( pj );
Error in Auswertung_3D_2p9_temp (line 399)
print('-f1', '-dpng', '-r600', sprintf('c:\folder\subfolder%d\filename', ii));
Do I make something obvious wrong? Furtheremore, beside a single variable, it is interesting how it would look like with more variables.
Jan
Jan 2012-9-20
The filename in the error message "'c:\older.png'" is not compatible to the posted code. Do you have write permissions on C:\ ?
What does "more variables" mean? For the usage of sprintf see:
help sprintf
doc sprintf

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by