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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 18 Gen 2013
Modificato: MathWorks Support Team
il 6 Ott 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.
Risposta accettata
MathWorks Support Team
il 18 Gen 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 Commento
Walter Roberson
il 30 Nov 2015
Modificato: MathWorks Support Team
il 6 Ott 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Schedule Model Components in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!