Reputation: 29
I save the data from my simulation with the to file block to a .mat file. When I start a new simulation, Simulink will overwrite the file if I dont set a new filename in the blocks properties.
Is it possible to add automaticly the current date / time to the filename? For the later usecase, i would be to extensive to set a filename for every new simulation manually.
thank you!
Upvotes: 0
Views: 901
Reputation: 795
You can create a callback that will be called whenever a simulation is started and update the filename pointed by the ToFile block
In your callback function (my_callback.m) :
block = find_system(bdroot,'Name','NameOfTheToFileBlock');
if ~isempty(block)
file_name = strcat('filename_', datestr(now, 'yyyy-mm-dd HH:MM:SS'), '.mat');
set_param(block{1}, 'Filename', file_name);
end
You can setup the callback programmatically that way :
set_param('your_model','StartFcn','my_callback');
Upvotes: 1