mit einem Klick
building-simulink-models
// Builds and edits Simulink, System Composer, Stateflow, and Simscape models. Use when modifying model structure, parameters, ports, connections, or Stateflow chart internals.
// Builds and edits Simulink, System Composer, Stateflow, and Simscape models. Use when modifying model structure, parameters, ports, connections, or Stateflow chart internals.
| name | building-simulink-models |
| description | Builds and edits Simulink, System Composer, Stateflow, and Simscape models. Use when modifying model structure, parameters, ports, connections, or Stateflow chart internals. |
| license | MathWorks BSD-3-Clause |
| metadata | {"author":"MathWorks","version":"1.1"} |
Use model_edit for Simulink, System Composer, and Simscape models (structural changes and parameter configuration). For Stateflow chart internals, use evaluate_matlab_code with the Stateflow API (see below).
model_query_paramsmodel_resolve_paramsmodel_read on the target scope to get block IDs and understand existing topology.model_edit with operations scoped to one subsystem level at a time.model_read on the scope to confirm the structure matches your intent.CRITICAL: If model_edit returns status: partial, run model_read immediately to determine if corrective action is needed.
refUse ref to name a block and #ref to reference it in later operations within the same call:
[{"op": "add_block", "type": "Gain", "name": "MyGain", "ref": "g1"},
{"op": "connect", "target": "blk_5.y1 -> #g1.u1"}]
The response created map shows ref → blk_id. In subsequent calls, use the blk_id (e.g., blk_42) — #ref only works within a single call.
model_overview or model_read. Block names can contain invisible newlines and trailing whitespace that cause hilite_system, open_system, and get_param to fail. Instead, resolve paths from blk_X IDs:
% blk_42 → use the number after "blk_" as the SID
blockPath = Simulink.ID.getFullName('<ModelName>:42');
hilite_system(blockPath)
open_system(blockPath)
get_param(blockPath, 'BlockType')
Simulink.BlockDiagram.arrangeSystem or use set_param for block positioning unless the user explicitly requests it. model_edit has a built-in autolayout engine that runs automatically after each call.layout_mode to model_edit. Use "full" when populating an empty scope (new model root, or a newly-created subsystem) for optimal block arrangement. Use "incremental" when adding blocks to a scope that already has existing blocks (preserves existing positions).Kp_SpeedController) instead of hardcoded numeric values. Define variables in model workspace or a .m init script.evaluate_matlab_code with set_param/add_block to bypass model_edit — it skips autolayout, undo tracking, and error recoveryopen_system rather than load_system to open models that are not already open, or when creating new models, unless the user explicitly asks otherwise or the model is a library. This ensures the user can see live edits as they happen.Prefer code-generation-safe names for blocks, signals, and variables:
a-z, A-Z, 0-9, underscore (_)Use the block's display name in the type field. Do not construct or guess library paths.
Gain, Sum, Constant, Integrator, SubSystem, ScopeVoltage Source, Resistor, DC Motor, Solver Configuration, 6DOF (Euler Angles)model_edit returns INVALID_TYPE: Fall back to the full library path from MATLAB documentation (e.g., ee_lib/Sources/Voltage Source)[{"op": "add_block", "type": "Voltage Source", "name": "V1", "ref": "v1"},
{"op": "add_block", "type": "Resistor", "name": "R1", "ref": "r1"},
{"op": "add_block", "type": "Electrical Reference", "name": "Gnd", "ref": "gnd"},
{"op": "add_block", "type": "Solver Configuration", "name": "Solver", "ref": "sc"}]
When working with these domains, read the corresponding reference file before editing:
reference/stateflow.md — model_edit can add Chart blocks but cannot edit chart internals. Use evaluate_matlab_code with the Stateflow API for states, transitions, junctions, and data. The reference covers API gotchas, subcharts, lint checks, and layout.reference/system-composer.md — Create models with systemcomposer.createModel, then use model_edit. Components use type: "SubSystem", ports use Bus Element blocks. The reference covers component creation, port wiring, and behavior model generation.reference/simscape.md — Physical connections use bidirectional <-> syntax. The reference covers connection semantics, port patterns, and initial target variables.Copyright 2026 The MathWorks, Inc.
Generate a standalone bug report that another developer can use to reproduce, investigate, and fix an issue. Use when the user says 'file a bug', 'write a bug report', 'report this issue', or asks to document a defect for handoff.
Generates draft requirements from Simulink models. Use when drafting or updating requirement artifacts from a model. Prefers Requirements Toolbox (.slreqx) when available; falls back to structured YAML.
Runs Simulink models programmatically for data exploration, parameter sweeps, and custom analysis using sim() with SimulationInput/SimulationOutput. Use when calling sim(), parsim, setExternalInput, setModelParameter, setVariable, or accessing logsout — any task producing simulation results for analysis (not pass/fail tests).
Specify algorithms for Model-Based Design: system specs, architecture specs, implementation plans, test plans. Use when creating specifications for controllers, signal processing, diagnostics, estimators, or other algorithms authored in Simulink, Stateflow, System Composer, or MATLAB Function blocks.
Specify plant models for closed-loop simulation: system specs, architecture, build plans, validation plans. Use when creating, updating, or reviewing plant model specifications, planning plant model architecture, or planning plant model validation.
Creates persistent Gherkin-based pass/fail tests for Simulink models and individual subsystems using model_test. Use when verifying expected behavior, writing regression tests, reproducing issues, or validating bug fixes with structured assertions. Requires Simulink Test.