How can I define some initialization commands in a s-function block in Simulink depending on a declarated variable from the Matlab command window ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuesta aceptada
Seth Popinchalk
el 2 de Feb. de 2011
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!