Main Content

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 ModelAdvisor.Check.supportExclusion and Simulink.ModelAdvisor.filterResultWithExclusion functions in the check definition file.

Update the Check Definition File

  1. Open the example that contains the supporting files for this example:

    openExample('slcheck/CreateAndDeployAModelAdvisorCustomConfigurationExample')

  2. Delete the supporting files from your working directory except for the AdvisorCustomizationExample model and the defineDetailStyleCheck.m and sl_customization.m files.

  3. Open the sl_customization file and modify it as follows:

    function sl_customization(cm)
    % SL_CUSTOMIZATION - Model Advisor customization demonstration.
    
    % Copyright 2019 The MathWorks, Inc.
    
    % register custom checks 
    cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
    
    % -----------------------------
    % defines Model Advisor Checks
    % -----------------------------
    function defineModelAdvisorChecks
    defineDetailStyleCheck;
    
  4. Open the defineDetailStyleCheck file.

  5. To update the Check whether block names appear below blocks check to exclude blocks during Model Advisor analysis, make two modifications to the defineDetailStyleCheck file.

    1. Enable the Check whether block names appear below blocks check to support check exclusions by using the ModelAdvisor.Check.supportExclusion property. After rec.setCallbackFcn(@DetailStyleCallback,'None','DetailStyle');, add rec.supportExclusion = true;. The first section of the function defineDetailStyleCheck now 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;
      

    2. Use the Simulink.ModelAdvisor.filterResultWithExclusion function 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);
      

  6. Save the DefineDetailStyleCheck file. If you are asked if it is OK to overwrite the file, click OK.

Create and Save Exclusions

  1. 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:

    Advisor.Manager.refresh_customizations();

  2. To open the model, double-click AdvisorCustomizationExample.slx.

  3. In the Modeling tab, select Model Advisor to open the Model Advisor.

  4. 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 Checks. The check fails.

  5. In the model window, right-click the X block and select Model Advisor > Exclude block only > Select Checks. Navigate to the Demo folder and select the Check whether block names appear below blocks check.

  6. In the Model Advisor Exclusion Editor, click Save to create an exclusion file.

  7. In the model window, open the Amplifier subsystem and right-click the GainBlock block and select Model Advisor > Exclude block only > Select Checks. Navigate to the Demo folder and select the Check whether block names appear below blocks check.

  8. In the Model Advisor Exclusion Editor, click Save to update the exclusion file.

Review Exclusions

  1. 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 Checks. 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.

  2. Close the model and the Model Advisor.

See Also

|

Related Examples

More About