Skip to content
Skills Library
Science & research · Automation

simulating-simulink-models

/simulating-simulink-models

Configures Simulink simulations non-destructively using SimulationInput objects — parameter overrides without modifying the model, batch sweeps via parsim, custom input signals via Dataset, and simulation data retrieval via logsout. Use when running sim()/parsim() with setVariable, setBlockParameter, setExternalInput, or when performing parameter sweeps and multi-run analysis. Not needed for one-shot simulations without configuration.

Licence
BSD-2-Clause
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

BSD-2-Clause, otwarta.

What it does and when to use it

Configures Simulink simulations non-destructively using SimulationInput objects — parameter overrides without modifying the model, batch sweeps via parsim, custom input signals via Dataset, and simulation data retrieval via logsout. Use when running sim()/parsim() with setVariable, setBlockParameter, setExternalInput, or when performing parameter sweeps and multi-run analysis. Not needed for one-shot simulations without configuration.

Original author description

Configures Simulink simulations non-destructively using SimulationInput objects — parameter overrides without modifying the model, batch sweeps via parsim, custom input signals via Dataset, and simulation data retrieval via logsout. Use when running sim()/parsim() with setVariable, setBlockParameter, setExternalInput, or when performing parameter sweeps and multi-run analysis. Not needed for one-shot simulations without configuration.

How it works

  1. When to Use
  2. When NOT to Use
  3. Minimal working pattern
  4. Setting parameters
  5. Input signals
  6. Discovering logged data
  7. Accessing logged data
  8. Multiple simulations
  9. Parallel simulation (parsim)
  10. Guardrails
Original SKILL.md headings · 153 lines, 648 words
SKILL.md preview
---
name: simulating-simulink-models
description: Configures Simulink simulations non-destructively using SimulationInput objects — parameter overrides without modifying the model, batch sweeps via parsim, custom input signals via Dataset, and simulation data retrieval via logsout. Use when running sim()/parsim() with setVariable, setBlockParameter, setExternalInput, or when performing parameter sweeps and multi-run analysis. Not needed for one-shot simulations without configuration.
license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md
metadata:
  author: MathWorks
  version: "1.2"
---

# Simulating Simulink Models with the sim Command

Use this skill when you need to **configure** a simulation non-destructively — parameter overrides, custom inputs, batch execution, or structured output access. For persistent, reusable pass/fail behavioral testing (especially of individual subsystems), use `testing-simulink-models` instead. For trivial one-shot simulations without configuration, a direct `sim()` call suffices without this skill.

## When to Use

- Overriding model or block parameters non-destructively (setVariable, setBlockParameter, setModelParameter) — without modifying the .slx file
- Passing custom input signals to root-level Inport blocks via setExternalInput with a Dataset
- Running parameter sweeps or batch simulations (SimulationInput arrays, parsim, Fast Restart)
- Accessing logged signal data (logsout) for analysis after simulation

## When NOT to Use

- Trivial one-shot simulations without parameter overrides or custom inputs — a direct `sim('ModelName')` call works without this skill
- Writing declarative Gherkin-based tests → use `testing-simulink-models`
- Testing an individual subsystem or component → use `testing-simulink-models` (requires Simulink Test; auto-creates a harness, compiles only the subsystem — much faster than `sim()` which always compiles the entire model)
- Adding, connecting, or deleting blocks → use `building-simulink-models`
- Checking model structure for unconnected ports → use `model_check` tool directly
- Generating requirements from model behavior → use `generate-requirement-drafts`

## Minimal working pattern

Always simulate using `Simulink.SimulationInput` and `Simulink.SimulationOutput`:

```matlab
in = Simulink.SimulationInput('MyModel');
in = in.setModelParameter('StopTime', '10');
out = sim(in);
```

## Setting parameters

Use `SimulationInput` methods to configure the simulation:

```matlab
% Model-level parameters (StopTime, SolverType, SimulationMode, etc.)
in = in.setModelParameter('StopTime', '10', 'SolverType', 'Fixed-step');

% Block parameters — resolve path from blk_X ID (never type block names manually)
blkPath = Simulink.ID.getFullName('MyModel:5');
in = in.setBlockParameter(blkPath, 'Gain', '5');

% MATLAB workspace variables used by the model
in = in.setVariable('Kp', 1.2);
```

## Input signals

Pass input signals through Inport blocks using a `Simulink.SimulationData.Dataset`. Elements are matched to Inport blocks **by index position** — the first element maps to the Inport with port number 1, the second to port number 2, and so on.

```matlab
dt = 0.01;
N = 1000;
t = dt*(0:N)';
u = sin(2*pi*t);

ts = timeseries(u, t);

ds = Simulink.SimulationData.Dataset;
ds{1} = ts;

in = in.setExternalInput(ds);
out = sim(in);
```

You can also use `timetable` as an input format:

```matlab
secs = seconds(t);
tt = timetable(secs, u);

ds = Simulink.SimulationData.Dataset;
ds{1} = tt;

in = in.setExternalInput(ds);
```

## Discovering logged data

First, discover what kinds of logged data the model produces using `who`, then inspect signal names within `logsout`:

```matlab
in = Simulink.SimulationInput('MyModel');
out = sim(in);

% See what logging properties exist (logsout, yout, tout, etc.)
who(out)

% List individual signal names within logsout
disp(out.logsout.getElementNames);
```

## Accessing logged data

Logged signals are available through `out.logsout`. Access them directly by name:

```matlab
% Plot a logged signal
plot(out.logsout.get('signalName').Values)

% Get time and data separately
sig = out.logsout.get('signalName').Values;
plot(sig.Time, sig.Data)
```

## Multiple simulations

When running many simulations, create an array of `Simulink.SimulationInput` objects:

```matlab
in = repmat(Simulink.SimulationInput('MyModel'),N,1);
for k = 1:N
    in(k) = Simulink.SimulationInput('MyModel');
    in(k) = in(k).setVariable('gain', gains(k));
end
out = sim(in);
```

To enable fast restart for iterative sweeps (compiles the model only once):

```matlab
out = sim(in, 'UseFastRestart', 'on');
```

## Parallel simulation (parsim)

To run multiple simulations in parallel, use `parsim` instead of looping over `sim`:

```matlab
for k = 1:N
    in(k) = Simulink.SimulationInput('MyModel');
    in(k) = in(k).setVariable('gain', gains(k));
end
out = parsim(in);
```

`parsim` also supports `'UseFastRestart','on'` for faster batch runs.

## Guardrails

- **Never** use `set_param`, `load_system`, or `open_system` to drive simulation — `SimulationInput` replaces all of these.
- **Never** wrap `SimulationOutput` access in `try-catch` or `isfield` — `sim` either returns a valid object or throws. `SimulationOutput` has no `isfield` method.
- **Never** create unnecessary intermediate variables for logged data — access directly via `out.logsout.get('name').Values`.
- **Always** use `in`/`out` as variable names for `SimulationInput`/`SimulationOutput`.
- **Always** use `setExternalInput` with a `Dataset` — don't pass comma-separated lists of variables.

----

Copyright 2026 The MathWorks, Inc.

----
Files in this package (2)
  • SKILL.md 6 KB
  • manifest.yaml 1 KB

Versions

RepositoryScoreLicence
This page · matlab/simulink-agentic-toolkit100BSD-2-Clause
3154410240smh-arch/aircraft-control-modeling100Apache-2.0

Database snapshot: 13.11.2026 · package version dd04bc216036 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100simulink-run-parallel-simulations
    Use this skill to run multiple Simulink simulations in parallel with parsim, batchsim, and DesignStudy. TRIGGER when: user asks for parameter sweep, sweeping/varying parameters across simulations, Monte Carlo study, batch simulation, running multiple simulations, parallel…
  • 100simulink-linearize
    Linearize Simulink models. Use when obtaining linear time invariant or linear parameter varying models from Simulink models.
  • 95simulink-automation
    Use when working with Simulink models — analyzing topology, inspecting parameters, modifying values, or managing model lifecycle via MATLAB Engine.
  • 100matlab-simulink
    Builds well-structured, research-grade MATLAB analysis scripts and Simulink simulation models for control systems, robotics, and soft computing research. Use this skill whenever the user wants to write MATLAB code, build a Simulink model, simulate a dynamic system, analyze…
  • 100roadrunner-scenario-simulating
    Expert guidance for simulating RoadRunner scenarios via the MATLAB programmatic API and Simulink co-simulation. Use when the user wants to run a simulation, step through a simulation, control actors during co-simulation, add observers, attach sensors, retrieve simulation logs,…
  • 95simulation-orchestrator
    Orchestrate multi-simulation campaigns including parameter sweeps, batch jobs, and result aggregation. Use for running parameter studies, managing simulation batches, tracking job status, combining results from multiple runs, or automating simulation workflows.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.