How do I set user-defined parameters in an Embedded MATLAB Function Block from the MATLAB command prompt in Simulink 6.0 (R14) and later versions?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 18 de En. de 2013
Editada: MathWorks Support Team
el 6 de Oct. de 2020
I have created a model with an Embedded MATLAB Function Block and would like add user-defined parameters for the block using the command line API.
Respuesta aceptada
MathWorks Support Team
el 18 de En. de 2013
To create an Embedded MATLAB Function Block from the command line, perform the following steps:
1. Use the FIND method to find the Embedded MATLAB function block (Stateflow.EMChart object) with the right name in any open models. If the block name is unique, execute the following command at the MATLAB prompt:
B = S.find('Name','myBlockName','-isa','Stateflow.EMChart');
If the block name is not unique, it is still possible to find the object using the FIND methos. For more information on this methos execute the following command at the MATLAB prompt:
web([docroot,'/toolbox/stateflow/api/find.html'])
2. Add extra inputs to the Embedded MATLAB Function block. To do this execute the following commands at the MATLAB prompt:
line1='function y = fcn(u,param1,param2)';
line2=' y = u*param1*param2;';
B.Script = line1;
B.Script = line2;
3. By default, those parameters will be Inputs, and you will have to change their scope to Parameter. To do that, get the handle to the inputs with the command:
ins = B.inputs;
4. "Ins" will be an array of structs, with the first one being the port input "u", and the rest will be your added inputs (in this case "param1" and "param2").
5. Set those added inputs' scopes to Parameter with the command:
set(ins(2),'Scope','Parameter');
set(ins(3),'Scope','Parameter');
NOTE: For newer versions (~R2012b), name of the following terms have changed :
a. Embedded MATLAB Function Block - is now called 'MATLAB Function Block'
b. Stateflow.EMChart - is now called 'Stateflow.Chart'
1 comentario
Walter Roberson
el 30 de Nov. de 2015
Editada: MathWorks Support Team
el 6 de Oct. de 2020
Embedded MATLAB Function Block was renamed in R2011a
I do not find the change to Stateflow.EmChart documented in the release notes so I do not know which version it occurred in.
Más respuestas (0)
Ver también
Categorías
Más información sobre Schedule Model Components en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!