Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 36 ยท Testing and Verification

Model Advisor, Modeling Guidelines and Static Checks in Simulink

Run the Simulink Model Advisor to find design and standards violations, choose check configurations, fix issues, add custom checks and follow modeling style guidelines for readable models.

Tests find wrong behavior; static checks find models that are risky, hard to read, hard to port or not allowed by a standard, without running a simulation. In Simulink the main tool is the Model Advisor. This lesson explains how to run it, what it checks, how to configure it for a team or a standard (MAAB, MISRA C, ISO 26262, DO-178C) and how to write simple style rules yourself. The product cannot run on this site, so the stand-ins are small Python linters that mimic what a check does on a model description.

What the Model Advisor is

The Model Advisor (Analysis > Model Advisor or Modeling > Model Advisor depending on the release; command modeladvisor('modelName')) scans a model and groups results by check. Each check ends in Passed, Warning, Failed or Not Run, with an explanation and often a Fix button. Core Simulink includes general checks; the Simulink Check product adds the checks for standards and the Model Metrics.

Types of checks:

  • By Product > Simulink: diagnostic settings, unconnected lines, disabled library links, solver settings, data types.
  • By Product > Embedded Coder: code generation settings, identifiers, hardware.
  • By Product > Simulink Check: modeling standards, MAAB style rules, naming, layout, DO-178C/ISO 26262 checklists, IEC 61508.
  • By Product > Simulink Coverage / Design Verifier: readiness checks (for example whether the model can be analyzed).
  • By Task: the same checks grouped as a workflow (Modeling Standards for MAAB, Code Generation Efficiency, Model Metrics).
flowchart LR
    M["Model"] --> A["Model Advisor<br/>check configuration"]
    A --> R["Report: pass / warning / fail"]
    R --> F["Fix: automatic or manual"]
    F --> M

Static checks give quick feedback before you run tests or generate code.

Run it

  1. Open the model; choose Model Advisor from the Modeling tab (or type modeladvisor in the command window).
  2. In the left tree select a folder of checks (for example By Task > Modeling Standards for MAAB) or the whole set. Tick the checks you want. The Run Checks button runs the selection.
  3. Read results in the right pane. Clicking a block or signal name in the report highlights it in the model.
  4. Use Fix (when available) to apply an automatic correction, or fix by hand and click Run This Check again.
  5. Generate report (HTML or PDF) with the results for a review package.

From a script:

MATLAB
res = ModelAdvisor.run('controller', {'mathworks.design.CheckAndSetDiagnostics'});
ModelAdvisor.summary('controller', 'mathworks.design.*');   % run a group

Check IDs (for example mathworks.maab.jc_0201) are listed in the documentation and in the Model Advisor tree when you hover.

Typical findings

Finding Why it matters
Unconnected input or output ports Likely a mistake; the model may run but behave unexpectedly
Signals with default names (signal1) or long, unclear names Hard to read in reports and code
Blocks using double where the target has no FPU Slow and large generated code
Use of Goto/From across the model Hidden data flow, hard to follow
Algebraic loops Solver iteration, no code for some targets
Unit Delay blocks with sample time inherit (-1) in a multi-rate model Ambiguous rates
Floating-point comparisons for equality (== on doubles) Fragile logic
Division by a signal with no protection Possible division by zero
Stateflow without default transitions, or with transitions that depend on drawing order Non-deterministic or hard to review
Unprotected Integrator or Delay with unset initial values Uninitialized-state surprises
Magic numbers in blocks instead of named parameters Hard to calibrate

Modeling standards

  • MAAB (MathWorks Automotive Advisory Board) style guidelines: widely used rules for naming (names must not use certain characters), layout (signals flow left to right, no lines crossing blocks), block usage and Stateflow, now maintained as the MathWorks Advisory Board (MAB) Control Algorithm Modeling Guidelines. Simulink Check implements them as checks.
  • MISRA C:2012 / 2023 applies to the generated code, not the model. Embedded Coder has checks for the code generation settings that support MISRA compliance; Polyspace Bug Finder/Code Prover analyzes the C code itself.
  • ISO 26262 (road vehicles), DO-178C (airborne software), IEC 61508 (industrial), EN 50128 (rail), IEC 62304 (medical): IEC Certification Kit gives tool qualification documents and checks that support these processes.
  • Company guidelines: most teams add their own naming, layout and library rules.

Configure for a project

Open Settings in the Model Advisor (gear icon, Model Advisor > Settings) and:

  1. Choose the checks to run (a configuration) and save them to a .json file, or to a configuration file in older releases (Edit configuration).
  2. Check Show report after run, Run Model Advisor on model save for early feedback.
  3. Set Parameter per check (for example, the maximum depth of subsystems or the maximum number of blocks per subsystem).
  4. Add exclusions (modeladvisor exclusion file) with a rationale for blocks or subsystems that deliberately break a rule.
  5. Share the configuration file via the project so all engineers use the same rules; run it in continuous integration (ModelAdvisor.run in a script and fail the build on any Failed check).

Custom checks

You can write your own check with the Model Advisor Customization API (the outline below omits the callback body; see the documentation for the full pattern): a function sl_customization registers a check, with a callback that finds blocks (find_system) and returns pass or fail, with result descriptions and optionally an automatic action.

MATLAB
function sl_customization(cm)
    cm.addModelAdvisorCheckFcn(@defineMyChecks);
end

function defineMyChecks
    rec = ModelAdvisor.Check('company.naming.1');
    rec.Title = 'Names of Inport blocks start with in_';
    rec.setCallbackFcn(@checkInportNames, 'None', 'StyleOne');
    mdladvRoot = ModelAdvisor.Root;
    mdladvRoot.publish(rec, 'Company checks');
end

Without the product, the stand-in below shows the logic of such a check on a plain data description of the model.

Python Stand-in: a naming and style linter for a model description

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the real tool the rules examine the model through the API and the Fix actions can change settings; here they only report.

Metrics and complexity

Model Metrics (Simulink Check: Analysis > Model Metrics Dashboard) count blocks, subsystem depth, Stateflow complexity (cyclomatic complexity), library links, and (with Requirements Toolbox and Simulink Test) requirements and test coverage. A Model Metrics Dashboard shows which parts of the design lack requirement links or tests, helping managers and reviewers see the status of a certification project.

The stand-in shows how a simple metric (cyclomatic complexity) comes from decision counts.

Python Stand-in: cyclomatic complexity from a list of decisions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A common team rule is to keep V(G) under 10 to 15 per subsystem, which also makes testing for MC/DC practical.

Style guidelines you can apply without any tool

  • Left to right, top to bottom signal flow; keep lines short; avoid crossing lines.
  • Name signals that cross subsystem boundaries; use camelCase or snake_case consistently; add units in names or descriptions (speed_mps).
  • Limit subsystem depth (3 to 4 levels) and block counts per level (about 30 to 50 for readability).
  • Use Bus objects for related signals; avoid many Mux/Demux.
  • Use named parameters in a data dictionary (.sldd) instead of numbers inside blocks; document ranges and units there.
  • Use library blocks and model references for reuse; avoid copy-paste.
  • Prefer Merge/Switch structures that are explicit to hidden Goto/From.
  • Add annotations and block descriptions that state intent.

Common mistakes

  • Running the Advisor once at the end instead of as part of daily work.
  • Disabling checks to make a report green instead of fixing or justifying.
  • One huge configuration nobody reads; configure the checks that matter for the project.
  • Mixing up model standards (MAAB) with code standards (MISRA C).
  • Fixing automatically without review: some fixes change behavior (data types, solver settings).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the Model Advisor do?

    It is a static analysis tool; many checks offer an automatic fix.
  2. 2. Which applies to the generated C code rather than to the model?

    MISRA C is a coding standard for C; the model-level style rules come from MAAB/MAB.
  3. 3. Why record a rationale when you exclude a block from a check?

    Justified exclusions are part of an auditable quality process.
  4. 4. What is a good way to share checks across a team?

    A shared configuration plus automated runs gives consistent enforcement.

Summary

  • The Model Advisor statically checks models; checks give Passed, Warning or Failed, with Fix actions, and run by product or by task.
  • Simulink Check adds MAAB/MAB, ISO 26262, DO-178C and IEC 61508 checks and metrics; MISRA C concerns the generated code (Polyspace).
  • Save a check configuration, share it through the project, justify exclusions and run it automatically.
  • Custom checks use the Model Advisor customization API.
  • Good style (naming, layout, data dictionary, limited depth and complexity) removes many findings before any tool runs.

Next: Requirements and formal verification