Clear Filters
Clear Filters

Possible to instantiate an object in the base workspace and use it in Simulink Embedded Matlab function?

2 views (last 30 days)
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?
obj.useMethod(); % Start using the object....
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 '' 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:
Launch diagnostic report.

Answers (0)


Find more on Simulink Functions 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!