ModelAdvisor.FormatTemplate
用于格式化模型顾问分析结果的模板
说明
使用 ModelAdvisor.FormatTemplate 类在模型顾问的分析结果窗格中设置检查结果的格式,以便在您创建的检查之间保持一致的外观。可以将分析结果格式化为表格或列表。
创建对象
描述
obj = ModelAdvisor.FormatTemplate( 创建 type)ModelAdvisor.FormatTemplate 类的对象。 是标识模板格式类型(列表或表格)的字符向量。type
您必须将结果对象返回给模型顾问,才能在分析结果窗格中显示格式化的结果。
注意
在检查回调中使用 ModelAdvisor.FormatTemplate 类。
输入参量
ModelAdvisor.FormatTemplate 的类型。
对象函数
addRow | 向模型顾问分析结果中添加表行 |
setCheckText | 向结果中添加检查描述 |
setColTitles | 在模型顾问分析结果中添加表列标题 |
setInformation | 向结果中添加子检查描述 |
setListObj | 向模型对象添加超链接的列表 |
setRecAction | 添加“建议的操作”部分和文本 |
setRefLink | 添加“另请参阅”部分和链接 |
setSubBar | 在子检查结果之间添加行 |
setSubResultStatus | 向检查或子检查结果中添加状态 |
setSubResultStatusText | 在结果中的状态下方添加文本 |
setSubTitle | 为结果中的子检查添加标题 |
setTableInfo | 向表中添加数据 |
setTableTitle | 在模型顾问分析结果中向表添加标题 |
示例
下列
sl_customization文件包含的代码可以创建ft1和ft2两个对象并使用它们来设置在表格和列表中运行检查的结果的格式。结果标识模型中的模块。function sl_customization(cm) % register custom checks cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks); 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.publish(rec, 'My_Demo'); 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_Demo文件夹中,选择 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 Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)