メインコンテンツ

ModelAdvisor.FormatTemplate

モデル アドバイザーの結果を書式設定するためのテンプレートを作成する

説明

ModelAdvisor.FormatTemplate オブジェクトは、モデル アドバイザーの解析結果ペインでのチェック結果を書式設定するためのクラスを定義することにより、複数のチェックの外観を統一します。これらのオブジェクトを使用して、解析結果をテーブルまたはリストとして書式設定できます。

作成

説明

obj = ModelAdvisor.FormatTemplate(type) は、ModelAdvisor.FormatTemplate クラスのオブジェクトを作成します。ここで、タイプはテンプレートの書式タイプ (ListTemplate または TableTemplate) を指定する文字ベクトルです。書式設定された結果を解析結果ペインに表示するには、結果オブジェクトをモデル アドバイザーに返します。

メモ

チェックのコールバックで ModelAdvisor.FormatTemplate クラスを使用します。

入力引数

すべて展開する

ModelAdvisor.FormatTemplate のタイプ。ListTemplate は、結果を単純なリストまたは調査結果のリストとして書式設定します。TableTemplate は、結果を構造化された複数属性データのテーブルとして書式設定します。

オブジェクト関数

addRowモデル アドバイザー解析結果で行をテーブルに追加
setCheckTextAdd description of check in Model Advisor analysis results
setColTitlesモデル アドバイザー解析結果で列タイトルをテーブルに追加
setInformationAdd description of subcheck in Model Advisor analysis results
setListObjモデル オブジェクトへのハイパーリンクのリストの追加
setRecActionAdd Recommended Action text in Model Advisor analysis results
setRefLink[参考] セクションおよびリンクを追加する
setSubBarサブチェックの結果と結果の間にラインを追加する
setSubResultStatusTextAdd text below the check or subcheck status in Model Advisor analysis results
setSubResultStatusステータスをチェックまたはサブチェックの結果に追加する
setSubTitle結果にサブチェックのタイトルを追加する
setTableInfoAdd data to table in Model Advisor analysis results
setTableTitleモデル アドバイザー解析結果でタイトルをテーブルに追加

すべて折りたたむ

この例では、slcustomization.m ファイルで ModelAdvisor.FormatTemplate クラスを使用して、チェック結果をモデル アドバイザーの結果ペインでテーブルおよびリストの両方として書式設定する方法について説明します。この例ではモデル内のすべてのブロックを識別し、2 つの書式設定テンプレート オブジェクトを使用して、それらのブロックを両方の書式で表示します。

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

バージョン履歴

R2009a で導入