Including Out-of-Scope Parameters within M S-functions
이전 댓글 표시
Hello community.
I've recently picked up a project from a PhD student who has been working on an estimator within Simulink. He uses Matlab S-functions for the estimator and model block, and has a separate script where he defines 100+ constant parameters.
As it stands, in order for the script to be able to recognize these parameters he reruns this parameter script during each callback function (initialize, update, outputs, etc.). This takes up 40% of my simulation time, and I'd like to remove it.
Is there a way to include common parameters within the S-Function without passing them, preferably from the workspace? They are frequently tuned, so its nice having a script file that sets them all, as opposed to an incredibly long set of arguments. Or I could save them all as a .mat file, but then I'd like to be able to just load it once somewhere and go rather than reload it during every callback function. Thanks!
채택된 답변
추가 답변 (1개)
Walter Roberson
2012년 10월 22일
1 개 추천
You could read them at initialization time, and store them in persistent variables.
I am seeing hints that there is a new-ish approach to this involving "work vectors". I have seen a few examples posted, but I have not read about them, so I do not know what the advantages over persistent variables would be.
댓글 수: 2
Kaustubha Govind
2012년 10월 23일
Persistent variables should not be used to store state in S-functions, because this can cause issues if there are multiple instances of the same S-function in a model - this is where work vectors come in - they are essentially similar to persistent variables, but are scoped to the instance of the S-function. However, for this particular situation, I think registering tunable parameters on the S-function is the right approach.
Jeremy
2012년 10월 25일
카테고리
도움말 센터 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!