Matlab: Good way to save an .m File to variable

693 Views Asked by At

Right now I am doing some optimizations which takes some time and I would like to save the results in a good way. As my code is constantly changing I would like to save one or two .m Files together with the results. Just as a backup if I have to see exactly what I was doing.

So my ideal case would be:

mFile1 = load('mFile1.m');
results = randn(100,100); %some other variables
save('allResults.mat')

So that all of that end up stored in one file. It might not be super memory saving but the couple of KB are worth it I think.

Ideally something like

disp(mFile1) 

would result in some easy readable output.

Any ideas how I could resolve that? Thanks Thomas

Ps: I could also use a version tracking system, but I don't want to do that as it will take always some effort to go to previous versions.

2

There are 2 best solutions below

0
On

Use a source control system. Software development, independent of your formal training, shall never be done without version control. The effort to switch from one to another version takes not more than one or two commands. Setting up a DVS is done within hours, if it's your first attempt.

Additionally you will be able to restore 'all' your files, environment. Just think of tracing changes, when your m files are buried in zip files together with some data. While using version control, tracing changes is an easy task.

0
On

Use source control as suggested by zellus.

However, to answer your question you can type your m-file.