metric matlab,Specify logic for metric data analysis

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值