1
votes

I am trying to programmaticaly add To File block to existing Simulink model.

open_system('myModel, 'loadonly');
add_block('simulink/Sinks/To File', 'myModel/MyFileBlock');

This was successful, but further steps are unclear:

How do I define input to the To File block?
How do I set parameters: 'File name', 'Variable name', etc.?

For parameters, I tried to specify optional comma-separated pairs of Name,Value arguments, like so:

add_block('simulink/Sinks/To File', 'myModel/MyFileBlock', 'File name', 'myOutput.m')

but I got error: ToFile block does not have a parameter named 'File name'.

I also tried

set_param(''myModel/MyFileBlock', 'File name', 'myOutput.m')

but got the same error.

1

1 Answers

1
votes

Here's a solution that should work, there may be a better way to do this:

open_system('myModel', 'loadonly');
add_block('simulink/Sinks/To File', 'myModel/MyFileBlock');
set_param('myModel/MyFileBlock','FileName','myOutput.mat');
set_param('myModel/MyFileBlock','MatrixName','myMatrix');
set_param('myModel/MyFileBlock','SaveFormat','Timeseries');
% etc...

You can find a list of the relevant block-specific properties in the documentation:

enter image description here