Right now I am putting the simulation function together with the .mat containing simulation results and parameters in a .zip file. The file is then the final output of my simulation function. This procedure ensures I can track down mistakes - kind of a primitive version control. Simulation function is usually about 10-100 lines of code.
It would be more elegant if I could load a single file and get everything - so, I would like to create a single .mat file that contains both the code file as well as the variables, and when loaded to put that code file in the current folder when loading the data. Is that possible (doesn't seem to be - I can't find anything but saving variables and figures to .mat)?
Putting the whole contents of the function in a variable is a possible alternative I am considering, but I don't find it very compelling as I can't easily read that code until I re-create the file.