How can I define some initialization commands in a s-function block in Simulink depending on a declarated variable from the Matlab command window ?

4 ビュー (過去 30 日間)
Indira
Indira 2011 年 2 月 2 日
Hi, I have a subsystem masked in Simulink which contains initialization commands that are used depending on a declared variable from the Matlab command window (called Bcaso) - I converted my subsystem into a s-function block, which does not depend on Bcaso. I need that my s-function block can be executed depending on Bcaso. Thanks!

採用された回答

Seth Popinchalk
Seth Popinchalk 2011 年 2 月 2 日
S-functions can include parameter inputs. There are examples of this for Level 2 MATLAB S-function, (msfcndemo_limintm) and C-MEX S-functions, (see sfundemos).
In a Level 2 MATLAB S-function, during "setup" set the number of dialog parameters:
block.NumDialogPrms = 3;
Anywhere you need to reference a parameter (for example) inside "InitConditions" you can access it through the block object:
block.ContStates.Data = block.DialogPrm(3).Data;
The parameters are passed into the block through the S-function block parameters, separated by commas.
For C-MEX S-functions, use ssSetNumSfcnParams in mdlInitializeSizes to set the number of parameters and ssGetSfcnParam to get a pointer to an mxArray anywhere you need to use it. C-MEX S-functions also need to do some parameter checking, so it can get a lot more complicated. See the SFCNDEMOS for examples.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by