save plot in folder

2 views (last 30 days)
Christos Tsouknidas
Christos Tsouknidas on 3 May 2015
Hello, In order to save some time writing my thesis I would like to make an function that has an input the folder name and the figure name in order to save automatically the plots from matlab. Normally I save using the command:
print('-depsc','C:\Users\Lenovo\Dropbox\THESIS\Latex\graphics\Chap2\wind.eps');
Can you please help me how I can write the function? I tried this but does not work.
function [ output_args ] = saveAsEps( folderName, fileName )
eval(['print -depsc ,C:\Users\Lenovo\Dropbox\THESIS\Latex\graphics\,'num2str(folderName),'\',num2str(fileName)','.eps']);
end
Thanks!

Answers (2)

Image Analyst
Image Analyst on 3 May 2015

Jan
Jan on 3 May 2015
"It doesn't work" is not a useful description. Better post the error messages or explain the difference between the results and your expectations.
What about this:
function saveAsEps(folderName, fileName)
print('-depsc', ...
fullfile('C:\Users\Lenovo\Dropbox\THESIS\Latex\graphics\', ...
folderName, [fileName, '.eps']));
end
Avoid eval under all circumstances, because there is always a better method. num2str is not useful here - most likely. There was a comma in the path inside the eval argument.
  1 Comment
Christos Tsouknidas
Christos Tsouknidas on 3 May 2015
Yes!! Thanks a lot guys! Jan Simon was answer was almost correct! I made one small change. I call the function like this : saveAsEps( 'Chap1' ,'wind' )
function [ output_args ] = saveAsEps( folderName,fileName )
print('-depsc', ...
fullfile('C:\Users\Lenovo\Dropbox\THESIS\Latex\graphics\',[folderName ...
,'\', fileName, '.eps']));
end

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!