Main Content

ModelAdvisor.FormatTemplate

Template for formatting Model Advisor analysis results

Description

Use the ModelAdvisor.FormatTemplate class to format the result of a check in the analysis result pane of the Model Advisor for a uniform look and feel among the checks you create. You can format the analysis results as a table or a list.

Creation

Description

obj = ModelAdvisor.FormatTemplate(type) creates an object of the ModelAdvisor.FormatTemplate class. type is a character vector identifying the format type of the template, either list or table.

You must return the result object to the Model Advisor to display the formatted result in the analysis result pane.

Note

Use the ModelAdvisor.FormatTemplate class in check callbacks.

Input Arguments

expand all

Type of ModelAdvisor.FormatTemplate.

Object Functions

addRowAdd row to table
setCheckTextAdd description of check to result
setColTitlesAdd column titles to table
setInformationAdd description of subcheck to result
setListObjAdd list of hyperlinks to model objects
setRecActionAdd Recommended Action section and text
setRefLinkAdd See Also section and links
setSubBarAdd line between subcheck results
setSubResultStatusAdd status to the check or subcheck result
setSubResultStatusTextAdd text below status in result
setSubTitleAdd title for subcheck in result
setTableInfoAdd data to table
setTableTitleAdd title to table in Model Advisor analysis results

Examples

collapse all

  1. The following sl_customization file contains code that creates two template objects, ft1 and ft2, and uses them to format the result of running a check in a table and a list. The result identifies the blocks in the model.

    function sl_customization(cm)
    
    % register custom checks
    cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
    
    % register custom factory group 
    cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);
    
    end
    
    
    % -----------------------------
    % defines Model Advisor Checks
    % -----------------------------
    function defineModelAdvisorChecks
    
    % Define and register a sample check 
    rec = ModelAdvisor.Check('mathworks.example.SampleDetailStyle');
    rec.Title = 'Sample check for Model Advisor using the ModelAdvisor.FormatTemplate';
    setCallbackFcn(rec, @SampleDetailStyleCallback,'None','DetailStyle');
    rec.setReportStyle('ModelAdvisor.Report.DefaultStyle');
    
    mdladvRoot = ModelAdvisor.Root;
    mdladvRoot.register(rec);
    
    end
    
    
    % -----------------------------
    % defines Model Advisor Tasks
    % -----------------------------
    function defineModelAdvisorTasks
    mdladvRoot = ModelAdvisor.Root;
     
    % --- sample factory group
    rec = ModelAdvisor.FactoryGroup('com.mathworks.sample.factorygroup');
    rec.DisplayName='My Group 1';
    rec.Description='Demo Factory Group';
    rec.addCheck('mathworks.example.SampleDetailStyle');
    mdladvRoot.publish(rec); % publish inside By Group list
    
    end
    
    
    % -----------------------------
    % Sample Check With Subchecks Callback Function
    % -----------------------------
    function [ResultDescription] = SampleDetailStyleCallback(system, CheckObj)
    
    % Initialize variables
    ElementResults = ModelAdvisor.ResultDetail.empty();
    
    % Perform the check actions
    allBlocks = find_system(system);
    [ResultDescription] = getFormattedTemplate(allBlocks);
    
    % Perform the subcheck actions - Result Details - Table
    if length(allBlocks) == 1
        % Add result details for detailed style check
        ElementResults(end + 1) = ModelAdvisor.ResultDetail;
        ElementResults(end).IsViolation = true;
        ElementResults(end).Description =  ['Find and report all blocks in a table. '...
            '(setInformation method - Description of what the subcheck reviews)'];
        ElementResults(end).Status =  ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)'];   
    else  
        for i=1:numel(allBlocks)
            ElementResults(end+1) = ModelAdvisor.ResultDetail;
            ElementResults(end).IsViolation = false;
            ElementResults(end).Format = 'Table';       
            ModelAdvisor.ResultDetail.setData(ElementResults(end),'SID',allBlocks{i});
            ElementResults(end).Description =  ['Find and report all blocks in a table. '...
                '(setInformation method - Description of what the subcheck reviews)'];
            ElementResults(end).Status = ['The model contains blocks. '...
                '(setSubResultStatusText method - Description of result status)'];
        end    
    end
    
    % Perform the subcheck actions  - Result Details - List
    if length(allBlocks) == 1
         ElementResults(end+1) = ModelAdvisor.ResultDetail;
         ElementResults(end).IsViolation = true;
         ElementResults(end).Description =  ['Find and report all blocks in a table. '...
            '(setInformation method - Description of what the subcheck reviews)'];
         ElementResults(end).Status =  ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)'];    
    else   
        for i= 1:numel(allBlocks) 
            ElementResults(end+1) = ModelAdvisor.ResultDetail;
            ElementResults(end).IsViolation = false;       
            ModelAdvisor.ResultDetail.setData(ElementResults(end),'SID',allBlocks{i});
            ElementResults(end).Description =  ['Find and report all blocks in a list. '...
                '(setInformation method - Description of what the subcheck reviews)'];
            ElementResults(end).Status = ['The model contains blocks. '...
                '(setSubResultStatusText method - Description of result status)'];  
        end    
    end
    
    %Set check result details
    CheckObj.setResultDetails(ElementResults);
    
    end
    
    function [ResultDescription] = getFormattedTemplate(allBlocks)
    ResultDescription={};
    
    % Create FormatTemplate object for first subcheck, specify table format
    ft1 = ModelAdvisor.FormatTemplate('TableTemplate');
    
    % Add information describing the overall check
    setCheckText(ft1, ['Find and report all blocks in the model. '...
        '(setCheckText method - Description of what the check reviews)']);
    
    % Add information describing the subcheck
    setSubTitle(ft1, 'Table of Blocks (setSubTitle method - Title of the subcheck)');
    setInformation(ft1, ['Find and report all blocks in a table. '...
        '(setInformation method - Description of what the subcheck reviews)']);
    
    % Add See Also section for references to standards
    setRefLink(ft1, {{'Standard 1 reference (setRefLink method)'},
        {'Standard 2 reference (setRefLink method)'}});
    
    % Add information to the table
    setTableTitle(ft1, {'Blocks in the Model (setTableTitle method)'});
    setColTitles(ft1, {'Index (setColTitles method)',
        'Block Name (setColTitles method)'});
    
    
    if length(allBlocks) == 1
        % Add status for subcheck
        setSubResultStatus(ft1, 'Warn');
        setSubResultStatusText(ft1, ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        setRecAction(ft1, {'Add blocks to the model. '...
            '(setRecAction method - Description of how to fix the problem)'});    
    else
        % Add status for subcheck
        setSubResultStatus(ft1, 'Pass');
        setSubResultStatusText(ft1, ['The model contains blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        for inx = 2 : length(allBlocks)
            % Add information to the table
            addRow(ft1, {inx-1,allBlocks(inx)});
        end    
    end
    
    % Pass table template object for subcheck to Model Advisor
    ResultDescription{end+1} = ft1;
    
    % Create FormatTemplate object for second subcheck, specify list format
    ft2 = ModelAdvisor.FormatTemplate('ListTemplate');
    
    % Add information describing the subcheck
    setSubTitle(ft2, 'List of Blocks (setSubTitle method - Title of the subcheck)');
    setInformation(ft2, ['Find and report all blocks in a list. '...
        '(setInformation method - Description of what the subcheck reviews)']);
    
    % Add See Also section for references to standards
    setRefLink(ft2, {{'Standard 1 reference (setRefLink method)'},
        {'Standard 2 reference (setRefLink method)'}});
    
    % Last subcheck, suppress line
    setSubBar(ft2, false);
    
    % Perform the subcheck actions
    if length(allBlocks) == 1
        % Add status for subcheck
        setSubResultStatus(ft2, 'Warn');
        setSubResultStatusText(ft2, ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        setRecAction(ft2, {'Add blocks to the model. '...
            '(setRecAction method - Description of how to fix the problem)'});
       
    else
        % Add status for subcheck
        setSubResultStatus(ft2, 'Pass');
        setSubResultStatusText(ft2, ['The model contains blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        % Add information to the list
        setListObj(ft2, allBlocks);
    end
    
    % Pass list template object for the subcheck to Model Advisor
    ResultDescription{end+1} = ft2;
    
    end
    
  2. Save the sl_customization file to your working directory.

  3. In the MATLAB command window, enter:

    Advisor.Manager.refresh_customizations

  4. Open a model.

  5. In the Modeling tab, select Model Advisor.

  6. In the By Task > My Group 1 folder, select Sample check for Model Advisor using ModelAdvisor.FormatTemplate.

  7. Click Run This Check.

    The following graphic displays the output as it appears in the Model Advisor when the check passes.

    Model Advisor output when the check passes

    The following graphic displays the output as it appears in the Model Advisor when the check warns.

    Model Advisor check output when the check warns

Alternatives

When you define a ModelAdvisor.Check object, for the CallbackStyle property, if you specify DetailStyle, you do not have to use the ModelAdvisor.FormatTemplate API or the other formatting APIs to the format results that appear in the Model Advisor report. DetailStyle also allows you to view results by block, subsystem, or recommended action.

If the default formatting does not meet your needs, use the ModelAdvisor.FormatTemplate API or the other formatting APIs. The ModelAdvisor.FormatTemplate class provides a uniform look and feel among the checks you create.

Introduced in R2009a