metric.Result
根据指定度量得出的结果
说明
metric.Result 对象包含指定度量的结果。
创建对象
描述
创建一个指向度量结果对象的句柄。metric_result = metric.Result
或者,如果您通过执行 metric.Engine 对象来收集结果,则在引擎对象上使用 getMetrics 函数会将收集到的 metric.Result 对象返回到一个数组中。
属性
由度量算法提供的用户数据,以字符串形式返回。
返回指定度量和工件的度量结果值,以整数、字符串、双精度向量或结构体的形式返回。有关模型测试度量及其结果值的列表,请参阅 模型测试度量。
用于计算结果的度量的度量标识符,以字符串形式返回。
示例: 'TestCasesPerRequirementDistribution'
计算度量的工程工件,以结构体或结构体数组的形式返回。对于该度量分析的每个工件,返回的结构体包含以下字段:
UUID- 工件的唯一标识符。Name- 工件名称。ParentUUID- 包含工件的文件的唯一标识符。ParentName- 包含工件的文件的名称。
数据类型: struct
度量结果的范围,以结构体的形式返回。范围是指收集度量结果的单位或组件。结构体包含以下字段:
UUID- 单元或组件的唯一标识符。Name- 单元或组件的名称。ParentUUID- 包含单元或组件的文件的唯一标识符。ParentName- 包含单元或组件的文件名。
数据类型: struct
自 R2025a 起
度量收集过程中返回的错误和警告,以结构体或结构体数组的形式返回。每个结构体包含以下字段:
Severity- 诊断消息的严重程度,返回值为"ERROR"或"WARNING"。Identifier- 诊断消息的标识符。Message- 诊断信息。
数据类型: struct
示例
使用 metric.Engine 对象收集工程中设计工件的度量结果。
打开一个包含要分析的模型的工程。对于此示例,在 MATLAB® 命令行窗口中,输入:
openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample"); openProject("cc_CruiseControl");
创建一个 metric.Engine 对象。您可以使用 metric.Engine 对象来收集当前工程的度量结果。
metric_engine = metric.Engine();
通过执行度量引擎,收集度量 slcomp.OverallCyclomaticComplexity 的结果。有关该度量的详细信息,请参阅模型可维护性度量。
execute(metric_engine,'slcomp.OverallCyclomaticComplexity');使用函数 getMetrics 访问结果。将结果对象数组赋值给 results 变量。
results = getMetrics(metric_engine,'slcomp.OverallCyclomaticComplexity');通过使用 results 数组中 metric.Result 对象的属性来访问度量结果数据。
for n = 1:length(results) disp(['Model: ',results(n).Scope.Name]) disp([' Overall Design Cyclomatic Complexity: ',num2str(results(n).Value)]) end
Model: cc_DriverSwRequest Overall Design Cyclomatic Complexity: 9 Model: cc_ThrottleController Overall Design Cyclomatic Complexity: 4 Model: cc_ControlMode Overall Design Cyclomatic Complexity: 22 Model: cc_CruiseControl Overall Design Cyclomatic Complexity: 1 Model: cc_LightControl Overall Design Cyclomatic Complexity: 4
有关如何收集设计工件度量的详细信息,请参阅以编程方式收集模型可维护性度量。
收集工程中基于需求的测试工件的度量结果。然后,使用 metric.Result 对象访问数据。
打开一个包含模型和测试工件的工程。对于此示例,在 MATLAB 命令行窗口中,输入:
openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample"); openProject("cc_CruiseControl");
创建一个 metric.Engine 对象。您可以使用 metric.Engine 对象来收集当前工程的度量结果。
metric_engine = metric.Engine();
更新 metric_engine 的追溯信息,确保工件信息是最新的。
updateArtifacts(metric_engine)
通过对 metric.Engine 对象使用 execute 函数,收集 'RequirementsPerTestCase' 度量的结果。
execute(metric_engine,'RequirementsPerTestCase');使用函数 getMetrics 访问结果。将结果对象数组赋值给 results 变量。
results = getMetrics(metric_engine,'RequirementsPerTestCase');通过使用数组中 metric.Result 对象的属性来访问度量结果数据。
for n = 1:length(results) disp(['Test Case: ',results(n).Artifacts(1).Name]) disp([' Number of Requirements: ',num2str(results(n).Value)]) end
版本历史记录
在 R2020b 中推出您可以使用 Diagnostics 属性返回度量收集过程中发生的诊断错误和警告。
metric.Result 对象不会为属性 Artifacts 和 Scope 返回字段 Type 和 ParentType。
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)