MATLAB: How to use the Model Advisor from command-line in Simulink and MATLAB

simulink

I want to use the Model Advisor not from the GUI but from command-line in order to be able to run it programatically.

Best Answer

You can create MATLAB file programs that run the Model Advisor programmatically. For example, you can create a MATLAB file program to check that your model passes a specified set of the Model Advisor checks every time you open the model or start a simulation or generate code from the model . For more information, see the Simulink.ModelAdvisor class:
Run Model Advisor from MATLAB file - Simulink
<http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/simulink.modeladvisor.html>
Use instances of this class in MATLAB file programs to run the Model Advisor, for example, to perform a standard set of checks. MATLAB software creates an instance of this object for each model that you open in the current MATLAB session. To get a handle to a model's Model Advisor object, execute the following command
MdlAdvHandle = Simulink.ModelAdvisor.getModelAdvisor(model);
where model is the name of the model or subsystem that you want to check. Your program can then use the Model Advisor object's methods to initialize and run the Model Advisor's checks.
Here is an example for a single check for Solvers:
function result = demo_modelAdvisor_CommandLine
model = 'rtwdemo_advisor1';
load_system(model);
% Get model advisor handle
MdlAdvHandle = Simulink.ModelAdvisor.getModelAdvisor(model);
% BaselineMode false is for verification, true is for baseline
% generation
MdlAdvHandle.setBaselineMode(true);
% As an example, here we only select the check of choice 'Check solver for
% code generation'
MdlAdvHandle.deselectCheckAll;
MdlAdvHandle.selectCheck('Check solver for code generation');
% Run the selected check
MdlAdvHandle.runCheck;
% Get check result
result = MdlAdvHandle.getCheckResult('Check solver for code generation');
You can add custom checks as explained here and follow the same procedure as above:
<http://www.mathworks.com/help/releases/R2016a/slvnv/ref/modeladvisor.check-class.html>