create a function to check multiple systems -凯发k8网页登录
you can use the modeladvisor.run
function to programmatically run checks on one or more models or subsystems. this example shows how to create a function that runs model advisor checks on multiple subsystems and then returns the number of failures and warnings.
this example also describes how you can modify the function to check multiple models or subsystems in parallel. if you have the parallel computing toolbox™ license, you can run this function in parallel mode to reduce the processing time.
write a function to run checks and return results
1. in the matlab® window, select new > function.
2. save the file as run_configuration.m
.
3. 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) %untitled summary of this function goes here % detailed explanation goes here outputarg1 = inputarg1; outputarg2 = inputarg2; end
4. delete the body of the function.
function [outputarg1,outputarg2] = run_configuration(inputarg1,inputarg2) end
5. replace the output arguments with [fail
,warn
] and the input argument with syslist
.
function [fail,warn] = run_configuration(syslist) end
6. inside the function, specify the model advisor configuration file.
filename = 'mycheckconfiguration.json';
7. the syslist
input is a list of systems for the model advisor to run checks on. call the modeladvisor.run
function on syslist
.
sysresultobjarray = modeladvisor.run(syslist,'configuration',filename);
8. determine the number of checks that return failures and warnings and output them to the fail
and warn
output arguments, respectively:
fail = 0; warn = 0; for i=1:length(sysresultobjarray) fail = fail sysresultobjarray{i}.numfail; warn = warn sysresultobjarray{i}.numwarn; end
the run_configuration
function now contains this content:
function [fail, warn] = run_configuration(syslist) %run_configuration check systems with model advisor % check systems given as input and return number of failures and warnings. filename = 'mycheckconfiguration.json'; % run the model advisor. sysresultobjarray = modeladvisor.run(syslist,'configuration', filename); fail = 0; warn = 0; for i=1:length(sysresultobjarray) fail = fail sysresultobjarray{i}.numfail; warn = warn sysresultobjarray{i}.numwarn; end end
test the function
1. save the run_configuration
function.
2. create sl_customization
file that is necessary for the custom configuration of checks in this example. for more information about custom configuration files, see .
copyfile customizationfile.m sl_customization.m f
3. save the subsystems that you want to run model advisor checks on to a variable called systems
.
systems = {'sldemo_auto_climatecontrol/heater control',... 'sldemo_auto_climatecontrol/ac control',... 'sldemo_auto_climatecontrol/interior dynamics'};
4. run the run_configuration
function on systems
.
[fail,warn] = run_configuration(systems);
running model advisor... updating model advisor cache... model advisor cache updated. for new customizations, to update the cache, use the advisor.manager.refresh_customizations method.... ... systems passed: 3 of 3 systems with warnings: 0 of 3 systems failed: 0 of 3 systems justified: 0 of 3 to view the summary report, use the 'modeladvisor.summaryreport(systemresultobjarray)' command. systemresultobjarray is the result of the modeladvisor.run command.
4. review the results by using the summary report or the disp
function:
to view the model advisor reports for each system, click the summary report link. this opens the model advisor command-line summary report.
to view the number of failures and warnings returned by the
run_configuration
function, look at thefail
andwarn
variables.
disp(['number of checks that return failures: ', num2str(fail)]);
number of checks that return failures: 0
disp(['number of checks that return warnings: ', num2str(warn)]);
number of checks that return warnings: 5
checking multiple systems in parallel
checking multiple systems in parallel reduces the processing time required by the model advisor. if you have a parallel computing toolbox™ license, you can check multiple systems in parallel on a multicore host machine.
to check multiple systems in parallel, call the modeladvisor.run
function with 'parallelmode
' set to 'on
'.
sysresultobjarray = modeladvisor.run(syslist,'configuration',filename,'parallelmode','on');
the parallel computing toolbox does not support 32-bit windows® machines.
each parallel process runs checks on one model at a time. when the model advisor runs in parallel mode, it does not support model data in the base workspace. model data must be defined in the model workspace or data dictionary.
see also
|