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

1 次查看(过去 30 天)

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?

采纳的回答

MathWorks Support Team
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 个)

类别

Help CenterFile Exchange 中查找有关 Create System Objects 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by