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 ビュー (過去 30 日間)
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
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
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 ExchangeSchedule Model Components についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by