matlab function call class in workspace

7 次查看(过去 30 天)
Hello,
First, I define a classdef named "ModelClass" with various properties, methods and functions.
Then I set global A = ModelClass and assign various values to properties of A.
A is now a global "1x1 ModelClass" value and saved in matlab workspace.
Now I'm trying to use A in Matlab Function in Simulink. Is it possible?
If yes, how can I do this.
Btw, I also have to generate S function of this Matlab Function. Therefore, I cannot use Interpreted Matlab Function.

回答(1 个)

Swastik Sarkar
Swastik Sarkar 2025-6-23
编辑:Swastik Sarkar 2025-6-23
In MATLAB Level-2 S-functions, the recommended method for maintaining persistent data across simulation steps is through the use of DWork vectors. These vectors are designed to store numeric or logical values. However, it is important to note that MATLAB class objects are not supported within DWork vectors. This limitation is documented in the official MathWorks Documentation:
As an alternative, the UserData property of a Simulink block may be used to store an instance of a MATLAB class. This property allows arbitrary MATLAB data, including class objects, to be associated with a block.
An example demonstrating this technique is available on MATLAB Central:
Further information on the UserData property can be found in the MATLAB documentation:

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by