Transfer of Fcn Block between Simulink and MATLAB

Hi, everyone. Before simulation I need to transmit to my Simulink model each time different function which is located in Fcn block. Of course I can pass variables to Fcn block but it is not sufficient. Thanks for your help.

 採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 10 月 17 日

2 投票

If you are using the Fcn block, you can simply change the setting for the "Expression" before each simulation. For example,
set_param('mymodel/Fcn', 'Expr', 'foo(u(1))')

2 件のコメント

Rostyk Spolyak
Rostyk Spolyak 2011 年 10 月 17 日
Thanks. How can I automate this process? Because I have hundreds of Fcn blocks and all of them use the same function.
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 18 日
You can use find_system to find blocks in your model that have BlockType=Fcn (see http://www.mathworks.com/help/toolbox/simulink/slref/find_system.html).
Here is a relevant blog post: http://blogs.mathworks.com/seth/2008/03/04/searching-in-simulink/

サインインしてコメントする。

その他の回答 (1 件)

Rostyk Spolyak
Rostyk Spolyak 2011 年 10 月 19 日

0 投票

Thank you for your answers :)
After executing "find_system" command I get a list with names of all Fcn blocks in my model. So, how can I change the 'Expression' in all blocks? I tried using "set_param" function but It works only with a models. Any idea?

4 件のコメント

Kaustubha Govind
Kaustubha Govind 2011 年 10 月 19 日
Rostyk: set_param works with models AND blocks. See my answer for how I specify the full path to the block to set the parameter.
Rostyk Spolyak
Rostyk Spolyak 2011 年 10 月 24 日
I suppose you dont understand my question.
Input argument for function 'set_param' must be the model or block. 'find_system' returns handles or paths to the objects.
I have nearly 50 Fcn blocks. So after executing find_system I get a list of all Fcn blocks. Then I must type 50 commands like this:
set_param('mymodel/Fcn1', 'Expression', 'u*128+5')
set_param('mymodel/Fcn2', 'Expression', 'u*128+5')
...
set_param('mymodel/Fcn50', 'Expression', 'u*128+5')
It is very boring to type everytime 50 commands. So I want to automate this process. I think I can make a script where I will write all this 50 commands and execute it everytime I need. Is there any other possibility? Maybe 'set_param' can receive as an object handle or vector of path to the objects?
Thanks for your help.
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 24 日
set_param cannot handle a cell array of block paths (although get_param can). But it's fairly trivial to loop through the array:
bh = find_system('mymodel', 'BlockType', 'Fcn');
for i = 1:numel(bh), set_param(bh{i}, 'Expression', 'u*128+5'), end
Rostyk Spolyak
Rostyk Spolyak 2011 年 10 月 24 日
Thanks. I`ll try this.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by