User`s guide
Quick Start Examples
25-11
Create Customized Pass/Fail Check with Fix Action
The following example shows how to create a Model Advisor pass/fail check with a fix
action. In this example, the Model Advisor checks Constant blocks. If a Constant block
value is numeric, the check fails. The Model Advisor is also customized to create a fix
action for the failed checks.
1
In your working directory, update the sl_customization.m file, as shown below.
This file contains three functions, each of which use the Model Advisor format
template:
• defineModelAdvisorChecks — Defines the check, creates input parameters,
and defines the fix action.
• simpleCallback — Creates the check that finds Constant blocks with numeric
values.
• simpleActionCallback — Creates the fix for Constant blocks that fail the
check.
function sl_customization(cm)
% --- register custom checks
cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
% --- defineModelAdvisorChecks function
function defineModelAdvisorChecks
mdladvRoot = ModelAdvisor.Root;
rec = ModelAdvisor.Check('exampleCheck');
rec.Title = 'Check Constant block usage';
rec.TitleTips = ['Fail if Constant block value is a number; Pass if '...
'Constant block value is a letter'];
rec.setCallbackFcn(@SimpleCallback,'None','StyleOne')
% --- input parameters
rec.setInputParametersLayoutGrid([1 1]);
inputParam1 = ModelAdvisor.InputParameter;
inputParam1.Name = 'Text entry example';
inputParam1.Value='VarNm';
inputParam1.Type='String';
inputParam1.Description='sample tooltip';
inputParam1.setRowSpan([1 1]);
inputParam1.setColSpan([1 1]);
rec.setInputParameters({inputParam1});
% -- set fix operation
myAction = ModelAdvisor.Action;
myAction.setCallbackFcn(@simpleActionCallback);
myAction.Name='Fix Constant blocks';
myAction.Description=['Click the button to update all blocks with'...