Open the model.
openExample('sldemo_mdlref_basic'); Create an slmetric.config.Configuration object.
CONF = slmetric.config.Configuration.new('name', 'Config');Get the default slmetric.config.ThresholdConfiguration object in
CONF.
TC = getThresholdConfigurations(CONF);
Add an slmetric.config.Threshold object to the
slmetric.config.ThresholdConfiguration object. This threshold is
for the mathworks.metrics.SimulinkBlockCount metric and the
Value property of the slmetric.metric.Results
object.
T = addThreshold(TC, 'mathworks.metrics.SimulinkBlockCount', 'Value');
An slmetric.config.Threshold object contains a default
slmetric.config.Classification object that corresponds to the
Compliant category. Use the
slmetric.metric.MetricRange class to specify metric values for the
Compliant, NonCompliant, and
Warning metric ranges.
C = getClassifications(T); % default classification is Compliant
C.Range.Start = 5;
C.Range.IncludeStart = 0;
C.Range.End = 100;
C.Range.IncludeEnd = 0;
C = addClassification(T,'Warning');
C.Range.Start = -inf;
C.Range.IncludeStart = 0;
C.Range.End = 5;
C.Range.IncludeEnd = 1
C = addClassification(T,'NonCompliant');
C.Range.Start = 100;
C.Range.IncludeStart = 1;
C.Range.End = inf;
C.Range.IncludeEnd = 0;
Use the validate method to validate the metric ranges
corresponding to the thresholds in the
slmetric.config.ThresholdConfiguration object.
If the ranges are not valid, you get an error message. In this example, the ranges
are valid.
Save the changes to the configuration file. Use the
slmetric.config.setActiveConfiguration function to activate this
configuration for the metric engine to use.
configName = 'Config.xml';
save(CONF,'FileName', configName);
slmetric.config.setActiveConfiguration(fullfile(pwd, configName));
Create an slmetric.Engine object, set the root in the model for
analysis, and collect data for the
mathworks.metrics.SimulinkBlockCount metric.
metric_engine = slmetric.Engine();
setAnalysisRoot(metric_engine, 'Root', 'sldemo_mdlref_basic');
execute(metric_engine, 'mathworks.metrics.SimulinkBlockCount');
Get the model metric data that returns an array of slmetric.metric.ResultCollection objects, res_col.
res_col = getMetrics(metric_engine, 'mathworks.metrics.SimulinkBlockCount');
Display the results for the mathworks.metrics.SimulinkBlockCount
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([' Classifications: ', result(m).Classifications.Classification.Category]);
disp([' Measures: ', num2str(result(m).Measures)]);
disp([' AggregatedMeasures: ', num2str(result(m).AggregatedMeasures)]);
end
else
disp(['No results for:', result(n).MetricID]);
end
disp(' ');
endFor ComponentPath: sldemo_mdlref_basic and
ComponentPath: sldemo_mdlref_counter, the results are
Compliant because of the values 12 and
18, respectively. For ComponentPath:
sldemo_mdlref_basic/More Info, the results fall under the
Warning category because of the 0 value.