Contenuto principale

ModelAdvisor.FormatTemplate

Create template for formatting Model Advisor results

Description

ModelAdvisor.FormatTemplate objects define a class for formatting the results of a check in the analysis result pane of the Model Advisor, providing a uniform look and feel across your checks. You can use these objects to format analysis results as either a table or a list.

Creation

Description

obj = ModelAdvisor.FormatTemplate(type) creates an object of the ModelAdvisor.FormatTemplate class, where type is a character vector that specifies the format type of the template, either ListTemplate or TableTemplate. To display the formatted result in the analysis result pane, return the result object to the Model Advisor.

Note

Use the ModelAdvisor.FormatTemplate class in check callbacks.

example

Input Arguments

expand all

Type of theModelAdvisor.FormatTemplate. ListTemplate formats results as a list for simple lists or findings. TableTemplate formats results as a table for structured multi-attribute data.

Object Functions

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

Examples

collapse all

This example shows how to use the ModelAdvisor.FormatTemplate class in slcustomization.m file to format check results as both a table and a list in the Model Advisor results pane. The example identifies all blocks in a model and displays them in both formats using two formatting template objects.

function sl_customization(cm)
% Register custom Model Advisor checks
cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
end

% Define and register Model Advisor checks
function defineModelAdvisorChecks
% Create and configure the check
rec = ModelAdvisor.Check("mathworks.example.SampleDetailStyle");
rec.Title = "Sample check for Model Advisor using the ModelAdvisor.FormatTemplate";
setCallbackFcn(rec,@SampleDetailStyleCallback,"None","DetailStyle");

% Publish the check
mdladvRoot = ModelAdvisor.Root;
mdladvRoot.publish(rec,"My_Demo");
end

% Callback function for the custom check
function [ResultDescription] = SampleDetailStyleCallback(system,CheckObj)
% Find all blocks in the system
allBlocks = find_system(system);

% Format the results using templates
ResultDescription = getFormattedTemplate(allBlocks);

% Set the formatted result details in the Model Advisor
CheckObj.setResultDetails(ResultDescription);
end

% Helper function to format results as a table and a list
function [ResultDescription] = getFormattedTemplate(allBlocks)
ResultDescription = {};

%% --- Table Template ---
% Create a table template formatting object
ft1 = ModelAdvisor.FormatTemplate("TableTemplate");
setCheckText(ft1,"Find and report all blocks in the model.");
setSubTitle(ft1,"Table of Blocks");
setInformation(ft1,"This table lists all blocks found in the model.");
setRefLink(ft1, {{"Standard 1 reference"},{"Standard 2 reference"}});
setTableTitle(ft1,"Blocks in the Model");
setColTitles(ft1,{"Index","Block Name"});

if numel(allBlocks) <= 1
    % No blocks found (only the model itself)
    setSubResultStatus(ft1,"Warn");
    setSubResultStatusText(ft1,"The model does not contain blocks.");
    setRecAction(ft1,{"Add blocks to the model."});
else
    % Add each block to the table
    setSubResultStatus(ft1,"Pass");
    setSubResultStatusText(ft1,"The model contains blocks.");
    for idx = 2:numel(allBlocks) % Skip the model itself (index 1)
        addRow(ft1,{idx-1,allBlocks{idx}});
    end
end

% Add the table template to the results
ResultDescription{end+1} = ft1;

%% --- List Template ---
% Create a list template formatting object
ft2 = ModelAdvisor.FormatTemplate("ListTemplate");
setSubTitle(ft2,"List of Blocks");
setInformation(ft2,"This list shows all blocks found in the model.");
setRefLink(ft2,{{"Standard 1 reference"},{"Standard 2 reference"}});
setSubBar(ft2,false); % Suppress the separating line

if numel(allBlocks) <= 1
    setSubResultStatus(ft2,"Warn");
    setSubResultStatusText(ft2,"The model does not contain blocks.");
    setRecAction(ft2,{"Add blocks to the model."});
else
    setSubResultStatus(ft2,"Pass");
    setSubResultStatusText(ft2,"The model contains blocks.");
    setListObj(ft2,allBlocks(2:end)); % List only blocks, skip model itself
end

% Add the list template to the results
ResultDescription{end+1} = ft2;
end

Version History

Introduced in R2009a