S-function Runtime-evaluation of parameters
Mostrar comentarios más antiguos
Hi
I have an S-function (written in c) which gets parameters through the S-function parameter-dialog. All parameters in this dialog are simply variables located in workspace. My ideal wish is now: When I change one of the parameters during simulation (by changing the corresponding workspace-variable) I want the S-function to use it without additional action. My solution so far is to mask the S-function and change a dummy-parameter inside this mask. This will force the mask to be initialized which again forces the S-function parameter-list to be evaluated, which again makes the updated values available inside the s-function.
It would be nice if I didn’t need to initialize the mask by doing this clicking around. Maybe some sort of “listener-functionality” exist?? Please note: Accessing the workspace from inside the S-function (which would solve this issue) is not an option due to code-generation-concerns.
Any good ideas?
Kind Regards Erik
Respuesta aceptada
Más respuestas (2)
Paulo Silva
el 20 de Abr. de 2011
On the S-Function try this:
eml.extrinsic('evalin');
var=evalin('base','var'); %var is a variable on the workspace
1 comentario
Erik Voigt
el 26 de Abr. de 2011
Mark
el 21 de Abr. de 2011
0 votos
This should be possible if you take two steps inside the S-function:
- You need to make the dialog parameters tuneable run-time parameters (This is a little bit complicated, but is covered by the documentation).
- You need to add a "mdlCheckParameters" function. This is an optional function for S-functions in general, but is likely required in your situation. Essentially, this function gets called when the S-function's dialog parameters get changed, and it provides you with an opportunity to "do whatever you need to do" (e.g. to validate the new values and propagate the effects of the changes to the rest of your code).
Although "mdlCheckParameters" will be called directly, it is also common and valid for your "mdlInitializeSizes" function to call it too, so that you don't have to have redundant code for validating the dialog parameters. (You don't generally call "mdlCheckParameters" blindly from "mdlInitializeSizes", because sometimes "mdlInitializeSizes" is being called just for propagating sizes, but there is an example in the documentation about the right checks to do in this case.)
1 comentario
Erik Voigt
el 26 de Abr. de 2011
Categorías
Más información sobre Simulink en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!