algorithm
Class: slmetric.metric.Metric
Namespace: slmetric.metric
(To be removed) Specify logic for metric data analysis
The Metrics Dashboard user interface, metricdashboard
function, slmetric
package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.
Description
Specify logic for metric algorithm analysis. Custom-authored metric algorithms are not called for library links and external MATLAB file components.
Input Arguments
Metric
— New model metric class
slmetric.metric.Metric
object
Model metric class you are defining for a new metric.
Component
— Component for metric analysis
Advisor.component.Component
object
Instance of Advisor.component.Component
for metric
analysis.
Output Arguments
Result
— Algorithm result data
array of slmetric.metric.Result
objects
Algorithm data, returned as an array of
slmetric.metric.Result
objects.
Examples
Create Metric Algorithm for Nonvirtual Block Count
This example shows how to use the
algorithm
method to create a nonvirtual block count
metric.
Using the createNewMetricClass
function, create a
metric class with the name nonvirtualblockcount
. The
function creates the nonvirtualblockcount.m
file in the
current working folder.
className = 'nonvirtualblockcount';
slmetric.metric.createNewMetricClass(className);
Open and edit the metric algorithm file
nonvirtualblockcount.m
. The file contains an empty
metric algorithm method.
edit(className);
Copy and paste the following code into the
nonvirtualblockcount.m
file. Save
nonvirtualblockcount.m
. The code provides a metric
algorithm for counting the nonvirtual
blocks.
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', ... 'GotoTagVisibility','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
Version History
Introduced in R2016aR2022a: Metrics Dashboard will be removed
The Metrics Dashboard user interface, metricdashboard
function, slmetric
package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.
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.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)