You can create a function to programmatically run multiple checks on a model. The function returns the number of failures and warnings.
In the MATLAB® window, select New > Function.
Save the file as run_configuration.m
.
In the function, right-click on untitled
and select
Replace function name by file name. The function name
is updated to run_configuration
.
function [outputArg1, outputArg2] = run_configuration(inputArg1,inputArg2)
Define the output and input arguments. For the output arguments, press Shift-Enter after entering each value to automatically update inlining instances in the function.
output_Arg1
as fail
output_Arg2
as warn
inputArg1, inputArg2
to
SysList
function [fail, warn] = run_configuration(SysList) fail = inputArg1; warn = inputArg2;
Inside the function, specify the list of checks to run using the example Model Advisor configuration file:
fileName = 'slvnvdemo_mdladv_config.mat';
Call the ModelAdvisor.run
function:
SysResultObjArray = ModelAdvisor.run(SysList,'Configuration',fileName);
Determine the number of checks that return warnings and failures:
fail = 0; warn = 0; for i=1:length(SysResultObjArray) fail = fail + SysResultObjArray{i}.numFail; warn = warn + SysResultObjArray{i}.numWarn;
The function should now look like this:
end function [fail, warn] = run_configuration(SysList) %RUN_CONFIGURATION Check systems with Model Advisor % Check systems given as input and return number of warnings and % failures. fail = 0; warn = 0; ModelAdvisor.setDefaultConfiguration('C:\temp\ma_configuration_standards.json'); SysResultObjArray = ModelAdvisor.run(SysList,'Configuration',fileName); for i=1:length(SysResultObjArray) fail = fail + SysResultObjArray{i}.numFail; warn = warn + SysResultObjArray{i}.numWarn; end end function
Save the function.
Test the function. In the MATLAB Command Window,
run run_configuration.m
on the sldemo_auto_climatecontrol/Heater
Control
subsystem:
[failures, warnings] = run_configuration(... 'sldemo_auto_climatecontrol/Heater Control');
Review the results. Click the Summary Report link to open the Model Advisor Command-Line Summary report.