Сбор метрических данных модели и доступ к ним sldemo_mdlref_basic.
Создание slmetric.Engine объект. Включите ссылочные модели и библиотеки в анализ и задайте корень в модели для анализа.
metric_engine = slmetric.Engine();
metric_engine.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;
setAnalysisRoot(metric_engine, 'Root', 'sldemo_mdlref_basic');
Сбор данных метрики модели
execute(metric_engine, 'mathworks.metrics.ExplicitIOCount');
Получение данных метрики модели, возвращающих массив slmetric.metric.ResultCollection объекты, res_col.
res_col = getMetrics(metric_engine, 'mathworks.metrics.ExplicitIOCount');
Отображение результатов для mathworks.metrics.ExplicitIOCount метрика.
for n=1:length(res_col)
if res_col(n).Status == 0
result = res_col(n).Results;
for m=1:length(result)
disp(['MetricID: ',result(m).MetricID]);
disp([' ComponentPath: ', result(m).ComponentPath]);
disp([' Value: ', num2str(result(m).Value)]);
disp([' AggregatedValue: ', num2str(result(m).AggregatedValue)]);
disp([' Measures: ', num2str(result(m).Measures)]);
disp([' AggregatedMeasures: ', num2str(result(m).AggregatedMeasures)]);
end
else
disp(['No results for:', result(n).MetricID]);
end
disp(' ');
endВот результаты:
MetricID: mathworks.metrics.ExplicitIOCount
ComponentPath: sldemo_mdlref_basic
Value: 3
AggregatedValue: 4
Measures: 0 3
AggregatedMeasures: 3 3
MetricID: mathworks.metrics.ExplicitIOCount
ComponentPath: sldemo_mdlref_basic/More Info
Value: 0
AggregatedValue: 0
Measures: 0 0
AggregatedMeasures: 0 0
MetricID: mathworks.metrics.ExplicitIOCount
ComponentPath: sldemo_mdlref_counter
Value: 4
AggregatedValue: 4
Measures: 3 1
AggregatedMeasures: 3 1
Для ComponentPath: sldemo_mdlref_basic, значение равно 3 потому что есть 3 выходы. Три выхода находятся во втором элементе Measures массив. slmetric.metric.AggregationMode является Max, так что AggregatedValue является 4 количество входов и выходов в sldemo_mdlref_counter. AggregratedMeasures массив содержит максимальное количество входов и выходов для компонента или подкомпонента.