Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Saving outputs to different folder than m-file.

Asked by Daniel on 28 Jun 2013

I have a script that I use on many different files saved in different folders. All of the files I want to keep separate I keep in different folders. I use the 'save' and 'saveas' functions in my script to keep my results. I have only one version of the script at a time, and change the inputs as appropriate for different data sets.

I would like to have the saved files to be save in the same folder I am pulling the inputs from, instead of the folder I have the m-file saved in. At this point I have not been able to successfully do this.

0 Comments

Daniel

Tags

Products

No products are associated with this question.

1 Answer

Answer by Matt Kindig on 28 Jun 2013
Accepted answer
%get the directory of your input files:
pathname = fileparts('/input/file');
%use that when you save
matfile = fullfile(pathname, 'output.mat');
figfile = fullfile(pathname, 'output.fig');
save(matfile, ...');
saveas(figfile, ...');

1 Comment

Daniel on 28 Jun 2013

Thank you. Works just as needed. I keep forgetting to connect multiple parts of strings together, like this for a file name.

Matt Kindig

Contact us