这个示例展示了如何使用模型度量API以编程方式收集模型的子系统和块计数度量。在为模型收集度量之后,您可以访问结果并将它们导出到一个文件中。
开放式VDP。
模型=“vdp”;Open_System(型号);
要在模型上收集度量数据,请创建度量标准引擎对象并呼叫执行
。
metric_engine = slmetric.engine();SetAnaliseRoot(Metric_Engine,'根'那“vdp”那'roottype'那“模型”);执行(metric_engine);
更新模型顾问缓存...模型顾问缓存更新。对于新的自定义,要更新缓存,请使用advisor.Manager.refresh_customizations方法。
使用getmetrics.
方法,指定要收集的指标。在此示例中,指定块计数和子系统数计数标准VDP.
模型。getmetrics.
返回Slmetric.Metric.ResultCollection.
对象。
res_col = getmetrics(metric_engine,{'mathworks.metrics.金宝appsimulinkblockcount'那......'mathworks.metrics.subsystemcount'});
创建单元格数组MetricData.
储存金钱
那ComponentPath
,价值
为度量结果。这金钱
是度量标准的标识符,是ComponentPath
是计算指标的组件的路径,以及价值
为公制值。编写一个循环来显示结果。
metricdata = {'MetriciD'那'componentpath'那'价值'};cnt = 1;为了n = 1:长度(res_col)如果res_col(n).status == 0结果= res_col(n).results;为了m = 1:长度(结果)disp(['MetriciD:',结果(m) .MetricID]);DISP(['ComponentPath:',结果(m).componentpath]);DISP([' 价值: ',num2str(结果(m).value)]);MetricData {CNT + 1,1} =结果(m).molricid;MetricData {CNT + 1,2} =结果(m).componentpath;MetricData {CNT + 1,3} =结果(m).Value;CNT = CNT + 1;结尾别的DISP([“没有结果:”,res_col(n).metricid]);结尾DISP('');结尾
MetricID:MathWorks.metrics.s金宝appimulinkblockcount.simulinkblockcount.
ComponentPath:VDP.
价值:13
MetricID:MathWorks.metrics.s金宝appimulinkblockcount.simulinkblockcount.
ComponentPath:VDP /更多信息
价值:1
MetricID:MathWorks.metrics.s金宝appimulinkblockcount.simulinkblockcount.
ComponentPath: vdp/More Info/Model Info
价值:1
MetricID:MathWorks.metrics.s金宝appimulinkblockcount.simulinkblockcount.
ComponentPath:VDP /更多信息/型号信息/ EmptySubSystem
价值:0
MetricID:MathWorks.metrics.subsystemcount.
ComponentPath:VDP.
价值:1
MetricID:MathWorks.metrics.subsystemcount.
ComponentPath:VDP /更多信息
价值:0
MetricID:MathWorks.metrics.subsystemcount.
ComponentPath: vdp/More Info/Model Info
价值:1
MetricID:MathWorks.metrics.subsystemcount.
ComponentPath:VDP /更多信息/型号信息/ EmptySubSystem
价值:0
出口MetricData.
结果金钱
那ComponentPath
,价值
到电子表格,使用可编程
写…的内容MetricData.
到MySpreadsheet.xlsx
。
filename =.'myspreadsheet.xlsx';t =表(metricdata);可编程(t,filename);
要将度量标准结果导出到XML文件,请使用exportMetrics
方法。对于每个度量标准结果,XML文件包括componentId.
那ComponentPath
那金钱
那价值
那聚合value.
,措施
。
filename =.'mymetricresults.xml';ExportMetrics(Metric_Engine,Filename)
关闭模型VDP.
。
bdclose(模型);
对于一个型号,您无法将度量数据收集到同一数据库文件中(即Metrics.db
文件)在多个平台上。
slmetric.engine.
|slmetric.Metric.Result.
|Slmetric.Metric.ResultCollection.