Possible to instantiate an object in the base workspace and use it in Simulink Embedded Matlab function?
1 view (last 30 days)
Show older comments
Is it possible to instantiate an object (using Matlab's Object Oriented Programming) in the base workspace, and then use that object in a Simulink embedded matlab function (without incurring a huge I/O penalty for having to load the object every time step)?
If I only have one matlab function then I can create the object inside of the embedded matlab function itself....however I'd like to use the object in multiple functions and I don't want to re-instantiate a new object in each function, and I don't see any way to pass the object around in Simulink.
I'm thinking of something like the following:
In the base workspace:
obj = myClassDef('name'); % Create the object in the matlab workspace, outside of Simulink
And then the Simulink embedded matlab function would have something like
persistent obj
if isempty(obj)
load(); % Not sure what this would look like; Load from file?
end
obj.useMethod(); % Start using the object....
obj.useProperty;
Is this possible? I already tried saving the object to it's own mat file and then using a load on the .mat file, but it won't work, I get the following error:
Found unsupported class for variable using function 'load'.
MATLAB class 'car' found at 'data.bmw' is unsupported.
Use the command 'whos -file bmw.mat' to view the variables in the MAT file.
Function 'MATLAB Function' (#23.62.77), line 5, column 12:
"load('bmw.mat')"
Launch diagnostic report.
0 Comments
Answers (0)
See Also
Categories
Find more on Configure and View Diagnostics 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!