S-function Runtime-evaluation of parameters
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Paulo Silva
2011년 4월 20일
On the S-Function try this:
eml.extrinsic('evalin');
var=evalin('base','var'); %var is a variable on the workspace
Mark
2011년 4월 21일
0 개 추천
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.)
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!