For the sake of simplicity I am using MATLAB scripts as configuration files in my application. This way I can use the function run
to load all variables into the workspace. Currently I am writing the code below out each and every time I need to load a configuration file.
configFile = [APP.PROJECT_DIR '/config/app.m'];
if exist(configFile, 'file') ~= 2
error('Missing configuration file for APP: [PROJECT ROOT DIR]/configFile/app.m')
end
run(configFile);
To reduce the amount of lines, I would like to place the above code in a standalone function. However if I do that the variables from the configuration file are loaded in that function instead of into the calling function. How could I manage to expose the workspace of a called function to the workspace of the calling function?
Basically what I want is the functionality of run
+ a check for file existince + custom error message if file does not exist.