Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 36 ยท Blocks and Models

Simulink Model Files, Layout and Modeling Style Guidelines

Learn Simulink file formats (.slx, .mdl), clean layout, naming, annotations, the Model Advisor, version control and comparing models, plus a small style-checker example.

A model that works is only half the job. Models are read, reviewed and changed far more often than they are written, and a messy diagram hides bugs. This lesson covers how Simulink stores models, how to keep diagrams readable, and which tools check your style and compare versions.

Simulink does not run on this site. Everything below describes the real product; the Python stand-in at the end is a toy "style checker" that mimics the kind of rule the Model Advisor applies.

File formats

Extension What it is
.slx The default model format since R2012a: a compressed package of XML parts. Smaller and faster than .mdl, and works better with source control tools that understand it
.mdl Older plain-text format, still readable. Convert by opening and saving as .slx
.slxp A protected model: others can use it but not see inside
.sldd Data dictionary
.slxc Simulation cache (generated, do not commit)
.slprj and slprj/ folder Generated simulation and code-generation artifacts
.mldatx Data Inspector session or test file

Save a model for an earlier release with Simulink.exportToVersion('model', 'model_R2020b.slx', 'R2020b'), with the caveat that newer features are removed or flagged.

Layout rules that help readers

  1. Signal flow left to right, top to bottom. Feedback runs along the bottom, right to left.
  2. Avoid crossing lines. Move or rotate blocks, or use a Goto/From pair only when a line would run across the whole model.
  3. Straight lines, grid alignment. Select blocks and use the alignment tools on the Format tab, or call Simulink.BlockDiagram.arrangeSystem(gcs) from MATLAB for a first draft, then fine-tune by hand.
  4. Show names that matter. Hide default block names such as Sum1 for obvious blocks and show names of important ones. Name every signal that you log or that crosses subsystem boundaries.
  5. Limit depth. Keep one level readable on a single screen (about 30 blocks); move detail into subsystems.
  6. Use color and Areas sparingly to mark meaning (for example sensors, controller, plant). Do not rely on color alone.

A readable diagram

Left to right Signals flow one way
Name signals Labels carry meaning
Subsystems One screen per level
Annotations Explain the why

Readers should not need you in the room.

1 / 2

Annotations and documentation

Add an annotation (a free text note on the canvas) by right-clicking an empty area > Add Annotation, or from the Format tab. Use them to state assumptions, units and sources of equations. Each block also has a Description and Document link in Block Properties (right-click > Properties), which show in the block tooltip. For model-wide notes use Modeling > Model Settings > Model Properties (description, version history, callbacks).

Good annotation:

TEXT
Drag force F = 0.5 * rho * Cd * A * v^2   [N]
Source: wind tunnel test T-2041. Valid for v < 60 m/s.

Bad annotation: "multiply by gain".

Naming conventions

  • Block names: nouns that say what the block is (Throttle Limiter, not Saturation1).
  • Signal names: short, with units in the name or an annotation if the team agrees (v_ms, T_cmd).
  • Be consistent: choose camelCase or snake_case and keep it. In generated C code, signal names become variable names, so valid identifiers matter.
  • Avoid names with newlines or special characters; block paths containing / need escaping by doubling it (//).

The Model Advisor

The Model Advisor (Modeling > Model Advisor, or modeladvisor('model')) runs checks and lists warnings and fixes. Check groups include By Product > Simulink (unconnected ports, solver settings, data type conversions), industry guideline sets (for example MAAB/JMAAB naming and layout rules, Embedded Coder checks) and standards such as IEC 61508 or ISO 26262 when the verification toolbox is installed. You can pick which checks to run, save a configuration and rerun it in a build script.

Version control and comparison

  • Keep models and their data in a Simulink Project (proj in MATLAB). Projects manage the path, shortcuts, startup/shutdown scripts and file dependencies, and have Git and SVN support built in.
  • Use Compare (right-click a file in the Project) or visdiff('a.slx','b.slx') to see structural differences as a report instead of a binary diff.
  • Merge conflicts in .slx files are not text-mergeable by hand; use Simulink's merge tool or make small, frequent commits and avoid two people editing the same model at once.
  • Commit generated folders only deliberately: add slprj/, *.slxc, and *.autosave to .gitignore.

Reuse and variants

Break repeated logic into library blocks or subsystems, keep parameters in one place, and use Variant Subsystems when the model must support alternatives (two engine types) in one file.

A style checker stand-in

The Model Advisor applies rules like "no default names" or "every unconnected port must be terminated". The Python below checks a small model description against a few such rules.

Python Stand-in: a tiny model style checker (Python)

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.

Python Stand-in: diff two versions of a model (Python)

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.

This is the spirit of visdiff: a report of structural changes, not a byte-by-byte comparison.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which file extension is the default Simulink model format today?

    .slx is the compressed package format used since R2012a; .mdl is the older text format.
  2. 2. What is the best direction for signal flow in a diagram?

    Consistent left-to-right flow makes diagrams easy to read.
  3. 3. What does the Model Advisor do?

    It runs selected checks (style, solver, standards) and suggests fixes.
  4. 4. Which folders or files should normally not be committed to version control?

    Generated caches can be recreated and change on every build.

Summary

  • Use .slx for models, .sldd for data, and keep generated folders out of version control.
  • Lay out diagrams left to right, name important blocks and signals, and document assumptions with annotations.
  • The Model Advisor checks guidelines; Simulink Projects and visdiff support teams.
  • Style rules are not decoration: readable models have fewer bugs.

Next: Signals, Dimensions and Data Types