MATLAB: How to automatically change the dataset logging filename each time I run the simulation

changefilenameinitfcnloggingsimulink

I would like to log signals from my Simulink model to a file for later analysis. I am trying to incorporate a timestamp into the filename so that each successive simulation run does not overwrite a previous results file. I have the checkbox next to 'Log Dataset data to file' in the configuration parameters selected and the model will successfully log to the static filename I specify in that dialog.
In order to dynamically update the output filename each time I run the model, I have tried calling 'set_param' from the InitFcn callback but get the following error:
Changing property 'LoggingFileName' is not allowed.
How can I achieve the goal of automatically changing the dataset logging filename each time I run the simulation?
 

Best Answer

When InitFcn is called, the 'LoggingFileName' value is already set and is thus considered a read-only parameter.
The desired behavior can be accomplished using a wrapper MATLAB script. For example:
for i = ...
set_param(...);
sim(model_name); % Programmatically simulate the model
end