Unique workspace for each instance of Interpreted MATLAB Function block?
Show older comments
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 Comments
Paul
on 18 Jan 2022
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
on 18 Jan 2022
Edited: Herschel Pangborn
on 18 Jan 2022
Paul
on 18 Jan 2022
Exactly how is a structure, or actually class object instances, loaded from the base workspace into the function?
Herschel Pangborn
on 18 Jan 2022
Accepted Answer
More Answers (1)
Walter Roberson
on 18 Jan 2022
0 votes
"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.
Categories
Find more on Discontinuities in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!