algorithm
指定度量数据分析的逻辑
说明
指定度量算法分析的逻辑。对于库链接和外部 MATLAB 文件组件,不调用以自定义形式创建的度量算法。
输入参数
Metric
— 新模型度量类
slmetric.metric.Metric
对象
为新度量定义的模型度量类。
Component
— 用于度量分析的组件
Advisor.component.Component
对象
用于度量分析的 Advisor.component.Component
的实例。
输出参数
Result
— 算法结果数据
slmetric.metric.Result
对象的数组
算法数据,以 slmetric.metric.Result
对象的数组形式返回。
示例
创建非虚拟模块计数的度量算法
此示例说明如何使用 algorithm
方法创建非虚拟模块计数度量。
通过使用 createNewMetricClass
函数,创建一个名为 nonvirtualblockcount
的度量类。该函数在当前工作文件夹中创建 nonvirtualblockcount.m
文件。
className = 'nonvirtualblockcount';
slmetric.metric.createNewMetricClass(className);
打开并编辑度量算法文件 nonvirtualblockcount.m
。文件包含一个空的度量算法方法。
edit(className);
将以下代码复制并粘贴到 nonvirtualblockcount.m
文件中。保存 nonvirtualblockcount.m
。该代码提供用于对非虚拟模块进行计数的度量算法。
classdef nonvirtualblockcount < slmetric.metric.Metric % nonvirtualblockcount calculate number of non-virtual blocks per level. % BusCreator, BusSelector and BusAssign are treated as non-virtual. properties VirtualBlockTypes = {'Demux','From','Goto','Ground', ... 'GotoTagVisiblity','Mux','SignalSpecification', ... 'Terminator','Inport'}; end methods function this = nonvirtualblockcount() this.ID = 'nonvirtualblockcount'; this.Version = 1; this.CompileContext = 'None'; this.Description = 'Algorithm that counts nonvirtual blocks per level.'; this.ComponentScope = [Advisor.component.Types.Model, ... Advisor.component.Types.SubSystem]; end function res = algorithm(this, component) % create a result object for this component res = slmetric.metric.Result(); % set the component and metric ID res.ComponentID = component.ID; res.MetricID = this.ID; % use find_system to get all blocks inside this component blocks = find_system(getComponentSource(component), ... 'FollowLinks','on', 'SearchDepth', 1, ... 'Type', 'Block', ... 'FollowLinks', 'On'); isNonVirtual = true(size(blocks)); for n=1:length(blocks) blockType = get_param(blocks{n}, 'BlockType'); if any(strcmp(this.VirtualBlockTypes, blockType)) isNonVirtual(n) = false; else switch blockType case 'SubSystem' % Virtual unless the block is conditionally executed % or the Treat as atomic unit check box is selected. if strcmp(get_param(blocks{n}, 'IsSubSystemVirtual'), ... 'on') isNonVirtual(n) = false; end case 'Outport' % Outport: Virtual when the block resides within % any SubSystem block (conditional or not), and % does not reside in the root (top-level) Simulink window. if component.Type ~= Advisor.component.Types.Model isNonVirtual(n) = false; end case 'Selector' % Virtual only when Number of input dimensions % specifies 1 and Index Option specifies Select % all, Index vector (dialog), or Starting index (dialog). nod = get_param(blocks{n}, 'NumberOfDimensions'); ios = get_param(blocks{n}, 'IndexOptionArray'); ios_settings = {'Assign all', 'Index vector (dialog)', ... 'Starting index (dialog)'}; if nod == 1 && any(strcmp(ios_settings, ios)) isNonVirtual(n) = false; end case 'Trigger' % Virtual when the output port is not present. if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'off') isNonVirtual(n) = false; end case 'Enable' % Virtual unless connected directly to an Outport block. isNonVirtual(n) = false; if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'on') pc = get_param(blocks{n}, 'PortConnectivity'); if ~isempty(pc.DstBlock) && ... strcmp(get_param(pc.DstBlock, 'BlockType'), ... 'Outport') isNonVirtual(n) = true; end end end end end blocks = blocks(isNonVirtual); res.Value = length(blocks); end end end
版本历史记录
在 R2016a 中推出
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)