Question

I'm processing a data set and running into a problem - although I xlswrite all the relevant output variables to a big Excel file that is timestamped, I don't save the code that actually generated that result. So if I try to recreate a certain set of results, I can't do it without relying on memory (which is obviously not a good plan). I'd like to know if there's a command(s) that will help me save the m-files used to generate the output Excel file, as well as the Excel file itself, in a folder I can name and timestamp so I don't have to do this manually.

In my perfect world I would run the master code file that calls 4 or 5 other function m-files, then all those m-files would be saved along with the Excel output to a folder names results_YYYYMMDDTIME. Does this functionality exist? I can't seem to find it.

Was it helpful?

Solution

There's no such functionality built in.

You could build a dependency tree of your main function by using depfun with mfilename. depfun(mfilename()) will return a list of all functions/m-files that are called by the currently executing m-file. This will include all files that come as MATLAB builtins, you might want to remove those (and only record the MATLAB version in your excel sheet).

As pseudocode:

% get all files:
dependencies = depfun(mfilename());
for all dependencies:
    if not a matlab-builtin:
        copyfile(dependency, your_folder)

As a "long term" solution you might want to check if using a version control system like subversion, mercurial (or one of many others) would be applicable in your case. In larger projects this is preferred way to record the version of source code used to produce a certain result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top