How can we have an "assert" function in a "matlab.System" class so it executes during code generation?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 1 May 2024
Answered: MathWorks Support Team
on 7 May 2024
We have a Simulink model that includes a MATLAB System block, that we would like to generate code for using Simulink Coder. In the "matlab.System" class file, we want to validate that a property, "Port Dimensions" is equal to a certain default value. If it isn't equal, we want the code generation to stop.
How can the "assert" function be included in the "matlab.System" class file, such that it is called during code generation?
Accepted Answer
MathWorks Support Team
on 1 May 2024
The "assert" function can be called using the "validatePropertiesImpl" method of the "matlab.System" class.
This method gets called during the build process, so it can trigger the "assert" function during code generation. To implement it, include this method in the "matlab.System" script, under "methods":
function validatePropertiesImpl(obj)
% Validate related or interdependent property values
assert(isequal(obj.PortDimensions,obj.DefaultVal));
end
For more information on the "validatePropertiesImpl" method, please refer to this link:
https://uk.mathworks.com/help/releases/R2024a/matlab/ref/matlab.system.validatepropertiesimpl.html
0 Comments
More Answers (0)
See Also
Categories
Find more on Create System Objects 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!