Exclude Blocks From Custom Checks
This example shows how to exclude blocks from custom checks. To save time
during model development and verification, you can exclude individual blocks from
custom checks during a Model Advisor analysis. To exclude custom checks from
Simulink blocks and Stateflow charts, use the
Simulink.ModelAdvisor.filterResultWithExclusion functions in
the check definition file.
Update the Check Definition File
Set your folder to a writeable directory.
Copy the script
prepare_cust_chk_codeto your current folder and run the script. The script copies the files necessary for this example to your current folder.
copyfile(fullfile(matlabroot,'examples','slcheck','main','prepare_cust_chk_code.m'),... 'prepare_cust_chk_code.m','f'); run('prepare_cust_chk_code.m');
To update the Check position of block names check to exclude blocks during Model Advisor analysis, make two modifications to the
Enable the Check position of block names check to support check exclusions by using the
rec.supportExclusion = true;. The first section of the
function defineDetailStyleChecknow looks like:
% Create ModelAdvisor.Check object and set properties. rec = ModelAdvisor.Check('com.mathworks.sample.detailStyle'); rec.Title = 'Check whether block names appear below blocks'; rec.TitleTips = 'Check position of block names'; rec.setCallbackFcn(@DetailStyleCallback,'None','DetailStyle'); rec.supportExclusion = true;
Simulink.ModelAdvisor.filterResultWithExclusionfunction to filter model objects causing a check warning or failure with checks that have exclusions enabled. To do this, modify the
DetailStyleCallback(system, CheckObj)function as follows:
% Find all blocks whose name does not appear below blocks violationBlks = find_system(system, 'Type','block',... 'NamePlacement','alternate',... 'ShowName', 'on'); violationBlks = mdladvObj.filterResultWithExclusion(violationBlks);
DefineDetailStyleCheckfile. If you are asked if it is OK to overwrite the file, click OK.
Create and Save Exclusions
In order for your customizations to be visible in the Model Advisor, you must refresh the Model Advisor check information cache. At the MATLAB command prompt, type this command:
To open the model, double-click
In the Modeling tab, select Model Advisor to open the Model Advisor.
If the By Product folder is not displayed in the Model Advisor window, select Show By Product Folder from the Settings > Preferences dialog box.
In the left pane of the Model Advisor window, select the By Product > Demo > Check whether block names appear below blocks check. In the right pane, select Run This Check. The check fails.
In the Model Advisor window, check that HighlightingHighlight Check Results is selected. The blocks causing the Check whether block names appear below blocks check failure are highlighted in yellow.
In the model window, right-click the
Xblock and select Model Advisor > Exclude block only > Check position of block names.
In the Model Advisor Exclusion Editor, click OK to create an exclusion file.
In the model window, open the
Amplifiersubsystem and right-click the
GainBlockblock and select Model Advisor > Exclude block only > Check position of block names.
In the Model Advisor Exclusion Editor, click OK to update the exclusion file.
In the Model Advisor, click Settings > Preferences > Show Exclusion Tab. Review the exclusions in the Exclusions tab.
In the left pane of the Model Advisor window, select the By Product > Demo > Check position of block names check. In the right pane, select Run This Check. The check now passes. In the right-pane of the Model Advisor window, you can see the Check Exclusion Rules that the Model Advisor applies during the analysis.
Close the model and the Model Advisor.