Possible to instantiate an object in the base workspace and use it in Simulink Embedded Matlab function?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Configure and View Diagnostics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!