simulink-integrate-python-code skill
Python Code bloğu kullanarak genel Python fonksiyonlarını, sınıflarını ve kütüphanelerini Simulink modellerine entegre edin.
- GitHub yıldızları
- 1.345
- Dosyalar
- 5
- Son commit
- 11 Kas 2026
- Lisans
- See LICENSE
- İzin verilen araçlar
- —
simulink-integrate-python-code skill ne işe yarar?
simulink-integrate-python-code bir agent skill'dir. Python Code bloğu kullanarak genel Python fonksiyonlarını, sınıflarını ve kütüphanelerini Simulink modellerine entegre edin.
Özet, skill'in SKILL.md dosyasından oluşturuldu.
simulink-integrate-python-code skilli hakkında
Bu SKILL, R2025a veya daha yeni sürümleri kullanan mühendislerin genel Python fonksiyonlarını, sınıflarını ve kütüphanelerini Simulink modellerine entegre etmesini sağlar. Geliştiricilerin Python Code bloğunu kullanarak bir simülasyon içindeki her bir zaman adımında Python kodu çalıştırmasına olanak tanır. Bu özellik, özellikle numpy veya scipy gibi üçüncü taraf kütüphaneleri doğrudan bir model içinde çağırmanız gerektiğinde veya simülasyon adımları boyunca kalıcı bir Python nesnesini veya sayısal durumu korumanız gerektiğinde oldukça kullanışlıdır.
Bir agent, kullanıcı standart MATLAB blokları ile kolayca yönetilemeyen özel Python mantığını çalıştırmak istediğinde bu yeteneği yüklemelidir. py.* çağrılarını kullanan MATLAB Function bloklarının aksine, Python Code bloğu Rapid Accelerator ve model reference Accelerator modlarını destekler. İş akışı; bir model oluşturmayı, OutputCode ve SampleTime gibi belirli parametrelere sahip bloğu eklemeyi, SymbolSpec API aracılığıyla portları tanımlamayı ve son olarak bileşenleri birbirine bağlamayı içerir. Bu süreç, paylaşılan MATLAB Python yorumlayıcısına dayanır ve Simulink bus yapılarını Python sözlüklerine (dictionary) dönüştürme dahil olmak üzere çeşitli veri tipi eşlemelerini destekler.
Bir agent bununla neler yapabilir
- 1Simülasyonda Python kütüphanelerini çalıştırmaBir Simulink modeli içerisinden bir Python fonksiyonunu veya numpy veya scipy gibi üçüncü taraf bir kütüphaneyi çalıştırın.
- 2Zaman adımları arasında durum korumaBir simülasyon süresi boyunca bir Python nesnesini veya sayısal bir durumu koruyun.
- 3Semboller aracılığıyla model portlarını yapılandırmaKapsam ve veri tiplerini ayarlamak için SymbolSpec API kullanarak bir Python bloğu için giriş ve çıkış portlarını tanımlayın.
- 4Yüksek hızlı simülasyon modlarını etkinleştirmeRapid Accelerator veya model reference Accelerator modu gerektiren modellerde Python mantığını kullanın.
Skill'in SKILL.md dosyasından yazılmıştır. Her kullanım durumu oradaki bir alıntı ile kontrol edilir.
simulink-integrate-python-code skill nasıl kurulur
Her komut, skill klasörünü istemcinin skills dizinine kopyalar. Yüklemek için istemciyi yeniden başlatın veya yeni bir oturum başlatın.simulink-integrate-python-code skill'ini Claude Code uygulamasına kur
~/.claude/skills/simulink-integrate-python-code/SKILL.md
$ npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code ~/.claude/skills/simulink-integrate-python-codesimulink-integrate-python-code skill'ini Claude Code (project) uygulamasına kur
.claude/skills/simulink-integrate-python-code/SKILL.md
$ npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code .claude/skills/simulink-integrate-python-codesimulink-integrate-python-code skill'ini Codex uygulamasına kur
~/.agents/skills/simulink-integrate-python-code/SKILL.md
$ npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code ~/.agents/skills/simulink-integrate-python-codesimulink-integrate-python-code skill'ini Gemini CLI uygulamasına kur
~/.gemini/skills/simulink-integrate-python-code/SKILL.md
$ npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code ~/.gemini/skills/simulink-integrate-python-codesimulink-integrate-python-code skill'ini Claude.ai uygulamasına kur
npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code simulink-integrate-python-code && zip -r simulink-integrate-python-code.zip simulink-integrate-python-code # claude.ai → Customize → Skills → + → Create skill → Upload a skill → simulink-integrate-python-code.zip
SKILL.md
GitHub'da görüntülePython Code Block Reference
Library path: simulink/User-Defined Functions/Python Code (R2025a+)
The Python Code block is the way to run Python inside a Simulink model. When a user asks to run a Python function, call a Python class, or use a Python library each timestep, this block is the tool — they may not name it explicitly.
Use it even when a MATLAB Function block or MATLAB System object calling py.*
(coder.extrinsic) would produce the same numbers: those cannot build in Rapid
Accelerator or model reference Accelerator mode, and they hide the Python behind
a MATLAB block. The Python Code block works in both modes.
It converts inputs to Python objects, builds a dict keyed by symbol name, calls
exec() with that dict as namespace, then converts outputs back to Simulink
types. The interpreter is shared with MATLAB py.* — same process, modules, and
state.
- Environment setup — pyenv, venvs, sys.path, module reloading
- Examples — verified programmatic patterns
- PythonObject patterns — class integration and persistent state
When to Use
- Running a line or block of Python each timestep inside a Simulink model
- Calling a Python function, class, or third-party library (numpy, scipy, …) from a model
- Persisting a Python object or numeric state across timesteps
- Passing a tunable parameter or a vector/matrix signal into Python
- The user describes the goal ("run my Python code in the model") without naming the block
When NOT to Use
- Pure MATLAB-side Python calls with no model involved — use
py.*directly, no block needed - MATLAB Function blocks or S-Functions — those are different mechanisms
- Running a pretrained deep-learning model (PyTorch/TensorFlow/ONNX) — use the Deep Learning Toolbox Model Predict blocks (PyTorch/TensorFlow/ONNX/Custom Python Model Predict), which run via Python co-execution and are configured through the block's model-file tabs, not
SymbolSpec - General Simulink model construction unrelated to Python — use the
building-simulink-modelsskill
Workflow
Build the block in this order — ports do not exist until symbols are defined, so wiring comes last. The build takes five tool calls; batch the operations in each call:
- Create and save the model (
evaluate_matlab_code) —model_editneeds an existing model file. - Add and configure all blocks — one
model_editcall. Put the code parameters (OutputCode,InitializeConditionsCode,TerminateCode,SampleTime) inadd_blockparams. The Python Code block is created with no ports. The response maps eachrefto itsblk_NID:[{"op":"add_block","type":"simulink/Sources/Constant","ref":"src","params":{"Value":"3"}},{"op":"add_block","type":"simulink/User-Defined Functions/Python Code","ref":"py","name":"Py","params":{"OutputCode":"y = u * 2.0","SampleTime":"1"}},{"op":"add_block","type":"simulink/Sinks/Out1","ref":"out"}] - Define symbols — one
evaluate_matlab_codecall; this creates the ports.SymbolSpecis a read-only handle reached only throughget_param(blk,'SymbolSpec'), andmodel_editcannot configure symbols — this is the one step that usesget_paramdirectly. Callss.addSymbol(...)and set each symbol'sScope/Type/Sizein place. - Wire — one
model_editcall using the returned IDs:[{"op":"connect","target":"blk_1.y1 -> blk_2.u1"},{"op":"connect","target":"blk_2.y1 -> blk_3.u1"}] - Simulate and read the result — one
evaluate_matlab_codecall. The simulation compiles the block, so it is the verification; skip separate inspection calls unless it fails.
The examples give the symbol definitions and code parameters for common patterns; read them only when the pattern isn't covered here.
To run the model programmatically and inspect results (sim/parsim,
Simulink.SimulationInput, logsout), use the simulating-simulink-models skill.
Block Parameters
| Parameter | Type | Notes |
|---|---|---|
InitializeConditionsCode |
string | Runs once at simulation start |
OutputCode |
string | Runs each timestep |
TerminateCode |
string | Runs once at simulation end |
SampleTime |
string | Default "-1" (inherited) |
SymbolSpec |
handle | Read-only param — get and mutate in place, never set_param back |
What survives from InitializeConditionsCode to OutputCode: only imported
modules (import m, import m as x, import pkg.sub) and Persistent symbols.
Everything else in the init namespace is discarded — from m import f bindings,
functions, classes, and plain variables (k = 3) raise NameError in
OutputCode. Use the module-qualified form (import m → m.f(...)), repeat
the from import in OutputCode, or store objects in a Persistent symbol.
SymbolSpec API
Class: Simulink.PythonFunctionBlock.SymbolSpec (handle object).
ss = get_param(blk, 'SymbolSpec');
sym = ss.addSymbol('name'); % Returns Symbol — then set properties
sym.Scope = 'Input';
sym.Type = 'double';
sym.Size = '1';
got = ss.getSymbol('name'); % Retrieve existing
ss.deleteSymbol('name'); % Remove
Handle object: mutations apply immediately to the block.
Symbol Properties
| Property | Values | Notes |
|---|---|---|
Name |
char | Variable name in Python namespace |
Scope |
'Input' 'Output' 'Parameter' 'Persistent' |
|
Type |
'double' 'single' 'int8' 'int16' 'int32' 'int64' 'uint8' 'uint16' 'uint32' 'uint64' 'boolean' 'string' 'Bus: <BusObject>' 'fixedpoint' 'PythonObject' |
PythonObject only for Persistent. Use lowercase 'boolean' — 'Boolean' is accepted by the setter but fails at compile ("not in scope"). A bus symbol names a Simulink.Bus object in the base workspace |
Size |
char | '1', '3', '[2 3]', '-1' (inherit) |
Label |
char | Port/mask display name |
PortNumber |
int | Port ordering |
Data Type Mapping
| Simulink | Python |
|---|---|
| scalar double | float |
| vector/matrix double | numpy.ndarray if numpy is available, else array.array. Shape follows Size ('[2 3]' ↔ (2, 3)); element (i,j) in MATLAB is [i-1, j-1] in Python — no transpose |
string |
str (output str becomes a MATLAB string). A root Inport fed from the workspace needs Interpolate off |
| bus (input) | dict keyed by element name — u["a"] |
| scalar integer | int |
| vector integer | numpy.ndarray if numpy is available, else array.array |
PythonObject (Persistent) |
any Python object |
Limitations
- No variable-size signals or array of buses
- No continuous sample time with persistent variables
- No Dataflow Subsystems
- No rapid accelerator in For Each Subsystems
- No backward stepping with persistent variables
- Code generation supported (Python C API) — requires dev headers + interpreter linkage
Copyright 2026 The MathWorks, Inc.
Bu becerideki dosyalar
5simulink-integrate-python-code skill soruları
simulink-integrate-python-code skill'ini Claude Code uygulamasına nasıl kurarım?
npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code ~/.claude/skills/simulink-integrate-python-code komutunu çalıştırın. Claude Code, skill'leri ~/.claude/skills (tüm projeler) veya .claude/skills (tek proje) konumundan yükler ve açıklaması görevle eşleştiğinde skill'i kullanır.
simulink-integrate-python-code skill'ini hangi istemciler kullanabilir?
Agent Skills biçimini okuyan her istemci: Claude Code, Codex, Gemini CLI ve claude.ai (ZIP olarak yükleyin). Skill içindeki betikler yalnızca istemcinin kod çalıştırmaya izin verdiği yerlerde çalışır.
Derin öğrenme çıkarımı için Python Code bloğunu kullanabilir miyim?
Hayır, PyTorch, TensorFlow veya ONNX gibi eğitilmiş sinir ağı modelleri için Deep Learning Toolbox Model Predict bloklarını kullanmalısınız.