Export Figure using Print
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
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
2012년 9월 20일
Matlab's makedir() command might be more convenient than calling a system function.
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
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 Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!