I have a script that runs a Simulink model repeatedly, and saves the inputs(some are randomly generated) and outputs of that run into cells in MATfiles. I want to be able to specify a run and load the corresponding outputs into the workspace. I can crudely extract the data, but I don't yet know how to label it as desired.
Each time the Simulink model is run it would output variables such as :
cat = [1 2 3];
dog{1} = [5 7 7];
dog{2} = [5 2 66];
What the script does is write directly to a MATfile for each variable on each run. I.e. There is a 'cat.mat' and 'dog.mat'. If the script did 100 simulations, loading cat.mat results in a cell array called cat, with dimensions [1 100]. cat{1} is the array from run 1, cat{2} is the array for run 2. Equally for dog (except this has more layers). Note I have 300+ variables and some are structures.
Issue 1 (minor):
I was hoping to be able to load part of the MATfile (using v-7.3) but it doesn't support cell indexing. I can get around this by loading the cell with () brackets, and then extracting it again with {} as an extra step.
Issue 2 (main issue):
I need to be able to evaluate the model at a given run. So I need to variables to have the exact names in the workspace. What I would like is to be able to request run 4, and to get workspace variables:
cat = cat{4} from the cat.mat file
dog = dog{4} from the dog.mat file
I have an array with the names of all the variables to cycle through (e.g. saveVar(1) = 'cat'; saveVar(2) = 'dog';) if that helps.*
Currently:
simRun = 4;
for k = 1:length(saveVars)
mSaves{k} = matfile(saveVars{k});
eval(saveVars{k}) = mSaves{k}.(saveVars{k})(simRun);
end
This treats 'eval' as a variable name and so it doesn't give me the results I want. Any advice or alternative approaches are welcome! I can also change the way the data is saved if necessary. Using MATLAB 2015a currently for compatibility with the model.