How to periodically change Simulink Output file name?
Hello,
I am trying to periodically output data from Simulink using the "To File" block, and I would like to use the current date and time as the name for each output file. Currently, I am trying to periodically call a function which determines the real-world time, converts that to a string, and uses the set_param command to change the output file name accordingly.
function [Y, M, D, H, MN, S] = fcn()
coder.extrinsic(‘now’);
coder.extrinsic(‘datevec’);
coder.extrinsic(‘sprintf’);
coder.extrinsic(‘set_param’);
[Y, M, D, H, MN, S] = datevec(now,’HH:MM:SS.FFF’);
date_time=[Y M D H MN S];
fname = sprintf(‘OutputFile_%04d_%02d_%02d_%02d_%02d_%02f.mat’, date_time);
set_param(‘untitled/To File’,’Filename’,fname);
end
Unfortunately, I am receiving the error message "Cannot change parameter ‘File name: (Filename)’ of ‘untitled/To File’ while simulation is running".
I have only been able to successfully use the set_param command while Simulink is not running, but I need to change my output file name during simulation. Is this possible? Is there a better way to approach this problem?
Thank you,
DrewHello,
I am trying to periodically output data from Simulink using the "To File" block, and I would like to use the current date and time as the name for each output file. Currently, I am trying to periodically call a function which determines the real-world time, converts that to a string, and uses the set_param command to change the output file name accordingly.
function [Y, M, D, H, MN, S] = fcn()
coder.extrinsic(‘now’);
coder.extrinsic(‘datevec’);
coder.extrinsic(‘sprintf’);
coder.extrinsic(‘set_param’);
[Y, M, D, H, MN, S] = datevec(now,’HH:MM:SS.FFF’);
date_time=[Y M D H MN S];
fname = sprintf(‘OutputFile_%04d_%02d_%02d_%02d_%02d_%02f.mat’, date_time);
set_param(‘untitled/To File’,’Filename’,fname);
end
Unfortunately, I am receiving the error message "Cannot change parameter ‘File name: (Filename)’ of ‘untitled/To File’ while simulation is running".
I have only been able to successfully use the set_param command while Simulink is not running, but I need to change my output file name during simulation. Is this possible? Is there a better way to approach this problem?
Thank you,
Drew Hello,
I am trying to periodically output data from Simulink using the "To File" block, and I would like to use the current date and time as the name for each output file. Currently, I am trying to periodically call a function which determines the real-world time, converts that to a string, and uses the set_param command to change the output file name accordingly.
function [Y, M, D, H, MN, S] = fcn()
coder.extrinsic(‘now’);
coder.extrinsic(‘datevec’);
coder.extrinsic(‘sprintf’);
coder.extrinsic(‘set_param’);
[Y, M, D, H, MN, S] = datevec(now,’HH:MM:SS.FFF’);
date_time=[Y M D H MN S];
fname = sprintf(‘OutputFile_%04d_%02d_%02d_%02d_%02d_%02f.mat’, date_time);
set_param(‘untitled/To File’,’Filename’,fname);
end
Unfortunately, I am receiving the error message "Cannot change parameter ‘File name: (Filename)’ of ‘untitled/To File’ while simulation is running".
I have only been able to successfully use the set_param command while Simulink is not running, but I need to change my output file name during simulation. Is this possible? Is there a better way to approach this problem?
Thank you,
Drew periodically change simulink output file name MATLAB Answers — New Questions