image thumbnail

msavename

by

 

19 Feb 2013 (Updated )

Creates a path to easily save or load your results no matter where your function is located

Test_msavename.m
%--------------------------------------------------------------------------
% Test file for msavename.m fucntion
% Creates a path to easily save or load your results no matter where your 
% function is located
% Shows three general examples
%--------------------------------------------------------------------------
% Author: Daniel R. Herber, Graduate Student, University of Illinois at
% Urbana-Champaign
% Date: 2/19/2013
%--------------------------------------------------------------------------
% 06/09/2013 v1.1 Documentation changes and example to reflect the functions 
%                 ability to aid with loading data
%--------------------------------------------------------------------------
%% Run your code
x = 0;
y = 1;

%% Get path
% 1. You want the current function or script path in new folder
path1 = msavename(mfilename('fullpath'),'Saved_Data');
% 2. You want a specific function or script path in function folder
path2 = msavename('Test_msavename','');
% Extra. You want to load data that is in the function folder
path3 = msavename(mfilename('fullpath'),'');

%% Display paths to see the output
disp(path1)
disp(path2)
disp(path3)

%% Use the path to save the results
save(strcat(path1,'Data1.mat'),'x','y') % note where Data1.mat is saved
save(strcat(path2,'Data2.mat'),'x','y') % note where Data2.mat is saved
disp('Data saved')

%% Use the path to load the data
load(strcat(path3,'msavename_test_data.mat'))
disp('Data loaded')

Contact us