Unique workspace for each instance of Interpreted MATLAB Function block?
显示 更早的评论
I have a Simulink model with several Interpreted MATLAB Function blocks that all call the same function. Within that function, I load a structure variable from the base workspace that is used in calculating the outputs. Each instance of the block within my model needs to load a different structure variable. I assume there is some overhead in loading these variables from the base workspace every time the function is called, so I'd prefer to just load them once when the simulation is initialized and save them within the function workspace as persistent variables. However, that doesn't seem possible because the function workspace is common among all the blocks that call this function. Is there any way to have each instace of the block call the same function but with a different workspace? Or are there other efficient ways to load base workspace variables into the Interpreted MATLAB Function block? Thanks!
4 个评论
Paul
2022-1-18
Do you already have an implementation that works and you're just trying to improve it?
If so, how does each instance of the function called in the Interpreted Matlab Function know which structture to load? And where is each structure loaded from and how are they loaded into the function?
Herschel Pangborn
2022-1-18
编辑:Herschel Pangborn
2022-1-18
Paul
2022-1-18
Exactly how is a structure, or actually class object instances, loaded from the base workspace into the function?
Herschel Pangborn
2022-1-18
采纳的回答
更多回答(1 个)
Walter Roberson
2022-1-18
0 个投票
"In this example, the top model uses a signal object in the MATLAB® workspace to define the error data store. This is necessary because data stores are visible across model boundaries only if they are defined by signal objects in the MATLAB workspace or a data dictionary. The model specifies code for the PreLoadFcn model callback parameter that creates the signal object. This code executes before the model loads."
So you can create data stores that self-initialize at load time, and you can route them as signals to become an additional parameter nto the function block.
类别
在 帮助中心 和 File Exchange 中查找有关 Discontinuities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
