How to Use Model Advisor in Simulink: Step-by-Step Guide
Use the
ModelAdvisor.run function or the Simulink menu to open the Model Advisor. It helps you check your model for best practices and compliance by running predefined or custom checks. You can view results, fix issues, and generate reports directly within Simulink.Syntax
The basic syntax to run Model Advisor on a Simulink model is:
ModelAdvisor.run(modelName): Runs all default checks on the specified model.ModelAdvisor.run(modelName, checkIDs): Runs specific checks identified bycheckIDs.ModelAdvisor.showReport(modelName): Opens the report window for the model.
Here, modelName is the name of your Simulink model as a string, and checkIDs is a cell array of check identifiers.
matlab
ModelAdvisor.run('myModel') ModelAdvisor.run('myModel', {'check1', 'check2'}) ModelAdvisor.showReport('myModel')
Example
This example shows how to open a Simulink model, run the Model Advisor checks, and display the report.
matlab
open_system('vdp') results = ModelAdvisor.run('vdp'); ModelAdvisor.showReport('vdp');
Output
Model Advisor report window opens showing check results for model 'vdp'.
Common Pitfalls
- Not opening the model before running Model Advisor causes errors.
- Using incorrect model names or misspelled check IDs leads to no checks running.
- Ignoring the report window means missing important suggestions.
- Running Model Advisor on very large models can take time; be patient.
Always save your model before running checks to avoid losing changes.
matlab
try ModelAdvisor.run('nonexistentModel') catch e disp('Error: Model not found. Please open the model first.') end % Correct way open_system('vdp') ModelAdvisor.run('vdp')
Output
Error: Model not found. Please open the model first.
Quick Reference
Use this quick guide to remember key Model Advisor commands:
| Command | Description |
|---|---|
| ModelAdvisor.run('modelName') | Run all default checks on the model |
| ModelAdvisor.run('modelName', {'checkID1'}) | Run specific checks by ID |
| ModelAdvisor.showReport('modelName') | Open the Model Advisor report window |
| open_system('modelName') | Open the Simulink model before running checks |
Key Takeaways
Always open your Simulink model before running Model Advisor checks.
Use ModelAdvisor.run to perform checks and ModelAdvisor.showReport to view results.
Check IDs let you run specific checks instead of all default ones.
Review the report carefully to improve your model quality and compliance.
Save your model before running checks to avoid losing unsaved changes.