Export Figure using Print

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일

0 개 추천

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일

0 개 추천

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2012년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by