How to programmatically set To File block parameters?

4 ビュー (過去 30 日間)
Danijel Domazet
Danijel Domazet 2020 年 5 月 12 日
回答済み: Fangjun Jiang 2020 年 5 月 12 日
Hi,
I am trying to programmatically add To File block to existing Simulink model.
open_system('myModel, 'loadonly');
add_block('simulink/Sinks/To File', 'myModel/MyFileBlock');
This was successfull, 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 件)

Fangjun Jiang
Fangjun Jiang 2020 年 5 月 12 日
The parameter name is "Filename" and "MatrixName". BTW, the file name should be *.mat, not *.m
Select the "To File" block in the model, run "get(gcbh)" in Command Window to see a list of parameters and take a guess.
To find them in document, run this "web(fullfile(docroot, 'simulink/slref/block-specific-parameters.html'))"
To connect the block to other block, you need to run add_line()

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by