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.

 Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 17 de Oct. de 2011
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 comentarios

Rostyk Spolyak
Rostyk Spolyak el 17 de Oct. de 2011
Thanks. How can I automate this process? Because I have hundreds of Fcn blocks and all of them use the same function.
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/

Iniciar sesión para comentar.

Más respuestas (1)

Rostyk Spolyak
Rostyk Spolyak el 19 de Oct. de 2011

0 votos

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 comentarios

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 el 24 de Oct. de 2011
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.
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 el 24 de Oct. de 2011
Thanks. I`ll try this.

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by