S-function Runtime-evaluation of parameters
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Jarrod Rivituso
il 20 Apr 2011
My understanding is that for efficiency reasons Simulink tries to avoid checking whether base workspace variables have changed during simulation.
You can force Simulink to check the workspace for parameter updates by updating the diagram (Edit -> Update Diagram). You can also do this from the command line:
>> set_param(gcs,'SimulationCommand','update')
I don't know if any true listener functionality currently exists.
Più risposte (2)
Paulo Silva
il 20 Apr 2011
On the S-Function try this:
eml.extrinsic('evalin');
var=evalin('base','var'); %var is a variable on the workspace
MarkB
il 21 Apr 2011
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.)
Vedere anche
Categorie
Scopri di più su Simulink Coder 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!