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:
