ModelAdvisor.FormatTemplate
用于格式化模型顾问分析结果的模板
说明
使用 ModelAdvisor.FormatTemplate
类在模型顾问的分析结果窗格中设置检查结果的格式,以便在您创建的检查之间保持一致的外观。可以将分析结果格式化为表格或列表。
创建对象
描述
obj = ModelAdvisor.FormatTemplate(
创建 type
)ModelAdvisor.FormatTemplate
类的对象。
是标识模板格式类型(列表或表格)的字符向量。type
您必须将结果对象返回给模型顾问,才能在分析结果窗格中显示格式化的结果。
注意
在检查回调中使用 ModelAdvisor.FormatTemplate
类。
输入参量
type
— 模板类型
ListTemplate
| TableTemplate
ModelAdvisor.FormatTemplate
的类型。
对象函数
addRow | 向模型顾问分析结果中添加表行 |
setCheckText | Add description of check to result |
setColTitles | 在模型顾问分析结果中添加表列标题 |
setInformation | Add description of subcheck to result |
setListObj | 向模型对象添加超链接的列表 |
setRecAction | Add Recommended Action section and text |
setRefLink | Add See Also section and links |
setSubBar | Add line between subcheck results |
setSubResultStatus | Add status to the check or subcheck result |
setSubResultStatusText | Add text below status in result |
setSubTitle | Add title for subcheck in result |
setTableInfo | Add data to table |
setTableTitle | Add title to table in Model Advisor analysis results |
示例
格式化模型顾问结果
下列
sl_customization
文件包含的代码可以创建ft1
和ft2
两个对象并使用它们来设置在表格和列表中运行检查的结果的格式。结果标识模型中的模块。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'); 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).ViolationType = 'warn'; 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).ViolationType = 'pass'; 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).ViolationType = 'warn'; 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).ViolationType = 'pass'; 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
将
sl_customization
文件保存到您的工作目录中。在 MATLAB 命令行窗口中,输入:
Advisor.Manager.refresh_customizations
打开一个模型。
在建模选项卡中,选择模型顾问。
在按任务 > My Group 1文件夹中,选择 Sample check for Model Advisor using ModelAdvisor.FormatTemplate。
点击运行此检查。
下图显示了检查通过时模型顾问中显示的输出。
下图显示了检查发出警告时模型顾问中显示的输出。
备选方法
当您定义 ModelAdvisor.Check
对象时,对于 CallbackStyle
属性,如果指定 DetailStyle
,则不必使用 ModelAdvisor.FormatTemplate
API 或其他格式 API 来格式化模型顾问报告中显示的结果。DetailStyle
还允许您按模块、子系统或建议的操作来查看结果。
如果默认格式不符合您的需要,请使用 ModelAdvisor.FormatTemplate
API 或其他格式 API。ModelAdvisor.FormatTemplate
类在您创建的检查之间提供一致的外观。
版本历史记录
在 R2009a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)