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)
Afficher commentaires plus anciens
MathWorks Support Team
le 1 Mai 2024
Réponse apportée : MathWorks Support Team
le 7 Mai 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?
Réponse acceptée
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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Create System Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!