How can we have an "assert" function in a "matlab.System" class so it executes during code generation?

10 vues (au cours des 30 derniers jours)

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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 1 Mai 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

Plus de réponses (0)

Catégories

En savoir plus sur Create System Objects dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by