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?
8 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2013-1-18
编辑: MathWorks Support Team
2020-10-6
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.
采纳的回答
MathWorks Support Team
2013-1-18
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 个评论
Walter Roberson
2015-11-30
编辑:MathWorks Support Team
2020-10-6
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Model Editing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!