Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)

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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 1 de Mayo de 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

Más respuestas (0)

Categorías

Más información sobre Create System Objects en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by