跳到正文
FunCoding

搜索

搜索文档、Skill 和 MCP

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.

数据库与数据1.2kskills-catalog/model-based-design-core/simulating-simulink-models/SKILL.md

安装

把这段话发给 Claude Code、Codex 或 Cursor。智能体会先检查安全性,你确认后才安装。

读取 https://funcoding.ai/skills/matlab/simulink-agentic-toolkit/simulating-simulink-models/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

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:

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

Setting parameters

Use SimulationInput methods to configure the simulation:

% 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.

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:

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:

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:

% 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:

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):

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

Parallel simulation (parsim)

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

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.


相似的 Skill

xlsx
anthropics/skills180k

xlsx

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.

数据库与数据

deprecation-and-migration
addyosmani/agent-skills103k

deprecation-and-migration

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

数据库与数据

host-observer
thedotmack/claude-mem98k

host-observer

Use this when fulfilling claude-mem observer jobs on Grok Bot: reply only skip_summary or one full observation XML, never prose.

数据库与数据

babysit
thedotmack/claude-mem98k

babysit

Watch a pull request or review cycle until it is ready to merge. Use when asked to babysit, monitor, or keep checking PR comments, reviews, and CI until all actionable issues are resolved.

数据库与数据

mem-search
thedotmack/claude-mem98k

mem-search

Search claude-mem's persistent cross-session memory database. Use when user asks "did we already solve this?", "how did we do X last time?", or needs work from previous sessions.

数据库与数据

Agent Cost Report
thedotmack/claude-mem98k

Agent Cost Report

Believable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.

数据库与数据