主要内容

slmetric.metric.createNewMetricClass

R2026b

命名空间: slmetric.metric

(即将删除)为自定义模型度量创建新度量类

以后的版本中将会删除度量仪表板、模型度量、slmetric API 以及对应的自定义项。有关详细信息,请参阅Migrating from Metrics Dashboard to Model Design Dashboards。

描述

slmetric.metric.createNewMetricClass(class_name) 在当前工作文件夹中创建一个 slmetric.metric.Metric 类。该新度量类用于定义自定义模型度量,并支持以下 Advisor.component.Types:

  • Model

  • SubSystem

  • ModelBlock

  • Chart

  • MATLABFunction

示例

示例

全部折叠

此示例说明如何创建新度量类 my_metric。

调用函数并提供新度量类的名称:

slmetric.metric.createNewMetricClass('my_metric')

该函数在当前工作文件夹中创建一个 my_metric.m 文件。

该文件包含 my_metric 的类定义,其中包括构造函数和一个空的度量 algorithm 方法。

classdef my_metric < slmetric.metric.Metric
    %my_metric Summary of this metric class goes here
    %   Detailed explanation goes here
    properties
    end
    
    methods
        function this = my_metric()
            this.ID = 'my_metric';
            this.ComponentScope = [Advisor.component.Types.Model, ...
                Advisor.component.Types.SubSystem];
            this.AggregationMode = slmetric.AggregationMode.Sum;
            this.CompileContext = 'None';
            this.Version = 1;
            this.SupportsResultDetails = false;
            
            %Textual information on the metric algorithm
            this.Name = '';
            this.Description = '';
            this.ValueName = '';
            this.AggregatedValueName = '';
            this.MeasuresNames = {};
            this.AggregatedMeasuresNames = {};
        end
        
        function res = algorithm(this, component)
            res = slmetric.metric.Result();	
            res.ComponentID = component.ID;
            res.MetricID = this.ID;
            res.Value = 0;
        end
    end
end

在 algorithm 中编写您的自定义度量算法。

当您的自定义度量类可以正常工作并通过测试后,使用 slmetric.metric.registerMetric 注册度量。

输入参数

全部折叠

您为自定义度量创建的新度量类的名称。

数据类型: char

版本历史记录

在 R2016a 中推出

全部折叠