Borrar filtros
Borrar filtros

Export Figure using Print

3 visualizaciones (últimos 30 días)
Timo
Timo el 20 de Sept. de 2012
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.

Respuestas (2)

Thomas
Thomas el 20 de Sept. de 2012
Editada: Thomas el 20 de Sept. de 2012
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 comentarios
Jan
Jan el 20 de Sept. de 2012
Matlab's makedir() command might be more convenient than calling a system function.
Thomas
Thomas el 20 de Sept. de 2012
Editada: Thomas el 20 de Sept. de 2012
true, Thanks Jan, I forgot about it.. Edited accordingly

Iniciar sesión para comentar.


Jan
Jan el 20 de Sept. de 2012
Editada: Jan el 20 de Sept. de 2012
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 comentarios
Timo
Timo el 20 de Sept. de 2012
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 el 20 de Sept. de 2012
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

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by