The following is an example code for the persistent memory storage:
The DWork vector with MATLAB files (which is equivalent to Work Vector) can be used for memory storage in Simulink. A model with 3 inputs and 2 outputs has been created from the template for Level-2 MATLAB file S-Function.
The following files are attached :
mysfcn.m
test2.mdl
For syntax in using DWork vector, refer to the function under 'DoPostPropSetup' in myfcn.m file.
The name, dimensions, datatypeID, complexity properties are defined there and the 'UsedAsDiscState' property has been set to 'false' (i.e used as continuous state).
block.Dwork(1).Name = 'x1';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0;
block.Dwork(1).Complexity = 'Real';
block.Dwork(1).UsedAsDiscState = false;
Under 'Outputs' function, 'block.Dwork(1).Data' has been added, so that the algorithm is adding the value each time and increasing the value of the output. You can see that in the Scope. The parameter is set to 5 in Level-2 S-Function, you can see that in the Display output.
Best Answer