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

5 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by