This example shows how to collect and access metric data for the model sldemo_mdlref_basic
.
Open the sldemo_mdlref_basic
model.
open_system('sldemo_mdlref_basic');
Create an slmetric.Engine
object and set the root in the model for analysis.
metric_engine = slmetric.Engine();
% Include referenced models and libraries in the analysis,
% these properties are on by default
metric_engine.ModelReferencesSimulationMode = 'AllModes';
metric_engine.AnalyzeLibraries = 1;
setAnalysisRoot(metric_engine, 'Root', 'sldemo_mdlref_basic')
Collect model metric data.
execute(metric_engine, 'mathworks.metrics.ExplicitIOCount');
Return the model metric data as an array of slmetric.metric.ResultCollection
objects and assign it to res_col
.
res_col = getMetrics(metric_engine, 'mathworks.metrics.ExplicitIOCount');
Display the results for the mathworks.metrics.ExplicitIOCount
metric.
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
For ComponentPath: sldemo_mdlref_basic
, the value is 3
because there are three outputs. The three outputs are in the second element of the Measures
array. The slmetric.metric.AggregationMode
is Max
, so the AggregatedValue
is 4
, which is the number of inputs and outputs to sldemo_mdlref_counter
. The AggregatedMeasures
array contains the maximum number of inputs and outputs for a component or subcomponent.