How can I use a variable to set the file name using Simulink's "too file" block?

15 views (last 30 days)
Hello,
I am using Matlab 2020a to create a model and place the pertaent data into a file. My plan is to automate running the model via Matlab. Each time the model is run via Matlab certain variables in the model are changed. This has worked perfectly thus far with the exception of changing the name of the data file writen via simulink's "too file" function. If I set the variable A="test.data" in matlab and set the file name field in "too file" to A (note the lack of quotes), the resulting file created will be called "A.data" rather than "test.data". I do not know how to fix this issue.
If this is a bug that is fixed in newer versions of Matlab please let me know as I do have access to the latest release but have not updated.
Thank you,
Ajay Mehta

Answers (1)

Fangjun Jiang
Fangjun Jiang on 14 Sep 2022
As for as I know, what you imagined can not be done. In your MATLAB script, you have to modify the parameter of the "ToFile" block to change the file name. Including this in the loop of your script should be able to achive what you want.
set_param('ToFileBlockPath','FileName','A1.mat')

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!