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 in 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 sl_customization.m file.

Update the sl_customization.m File

  1. To open the example model, at the command prompt, type slvnvdemo_mdladv.

  2. In the model window, double-click View demo sl_customization.m.

  3. To exclude the custom check Check Simulink block font from blocks during Model Advisor analysis, make three modifications to the sl_customization.m file.

    1. Enable the Check Simulink block font check to support check exclusions by using the ModelAdvisor.Check.supportExclusion property. You can now exclude the check from model blocks. After rec.setInputParametersLayoutGrid([3 2]);, add rec.supportExclusion = true;. The check 1 section of the function defineModelAdvisorChecks now looks like:

      % --- sample check 1
      rec = ModelAdvisor.Check('com.mathworks.sample.Check1');
      rec.Title = 'Check Simulink block font';
      rec.TitleTips = 'Example style three callback';
      rec.setCallbackFcn(@SampleStyleThreeCallback,'None','StyleThree');
      rec.setInputParametersLayoutGrid([3 2]);
      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, there are two locations in the sl_customization.m file to modify, both in the [ResultDescription, ResultDetails] = SampleStyleThreeCallback(system) function:

      • After both instances of

        searchResult = setdiff(allBlks, regularBlks);

        add

        searchResult = mdladvObj.filterResultWithExclusion(searchResult);
      • In the first location, the function now looks like:

        % find regular font name blocks 
        regularBlks = find_system(allBlks,'FontName',regularFontName);
        
        % look for different font blocks in the system
        searchResult = setdiff(allBlks, regularBlks);
        searchResult = mdladvObj.filterResultWithExclusion(searchResult); 
        if ~isempty(searchResult)

      • In the second location, the function now looks like:

        % find regular font size blocks 
        regularBlks = find_system(allBlks,'FontSize',regularFontSize);
        % look for different font size blocks in the system
        searchResult = setdiff(allBlks, regularBlks);
        searchResult = mdladvObj.filterResultWithExclusion(searchResult);
        if ~isempty(searchResult)

  4. Save the sl_customization.m file. If you are asked if it is OK to overwrite the file, click OK.

Create and Save Exclusions

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

    Note

    If the By Product folder is not displayed in the Model Advisor window, select Show By Product Folder from the Settings > Preferences dialog box.

  2. In the left pane of the Model Advisor window, select the By Product > Demo > Check Simulink block font check. In the right pane, select Run This Check. The check fails.

  3. In the Model Advisor window, click the Enable highlighting button (). The blocks causing the Check Simulink block font check failure are highlighted in yellow.

  4. In the model window, right-click the X block and select Model Advisor > Exclude block only > Check Simulink block font.

  5. In the Model Advisor Exclusion Editor, click OK to create the exclusion file.

  6. In the model window, right-click the Input block and select Model Advisor > Exclude block only > Check Simulink block font.

Review Exclusions

  1. In the Model Advisor Exclusion Editor, click OK to update the exclusion file.

  2. In the left pane of the Model Advisor window, select the By Product > Demo > Check Simulink block font 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 during the analysis.

  3. Close slvnvdemo_mdladv.

See Also

|

Related Examples

More About