I need to analyse several sets of data which are associated with different parameter sets (one single set of parameters for each set of data). I’m currently struggling to find a good way to store these parameters such that they are readily available when analysing a specific dataset.
The first thing I tried was saving them in a script file parameters.m in the data directory and load them with run([path_to_data,'/parameters.m']). I understand, however, that this is not good coding practice and it also gave me scoping problems (I think), as changes in parameters.m were not always reflected in my workspace variables. (Workspace variables were only changed after Clear all and rerunning the code.)
A clean solution would be to define a function parameters() in each data directory, but then again I would need to add the directory to the search path. Also I fear I might run into namespace collisions if I don’t give the functions unique names. Using unique names is not very practical on the other hand…
Is there a better solution?
So define a
structorcell arraycalledparametersand store it in the data directory it belongs in. I don’t know what your parameters look like, but ours might look like this:and I can write
or even
The online help reveals how to use
-structto store fields from a structure as individual variables should that be useful to you.Once you’ve got the parameters saved you can load them with the
loadcommand.To sum up: create a variable (most likely a struct or cell array) called
parametersandsaveit in the data directory for the experiment it refers to. You then have all the usual Matlab tools for reading, writing and investigating the parameters as well as the data. I don’t see a need for a solution more complicated than this (though your parameters may be complicated themselves).