simulink-integrate-python-code skill
✓ 인증됨Python Code 블록을 사용하여 일반 Python 함수, 클래스 및 라이브러리를 Simulink 모델에 통합합니다.
- GitHub 스타
- 1,345
- 파일
- 5
- 마지막 커밋
- 2026년 11월 11일
- 라이선스
- See LICENSE
- 허용된 도구
- —
simulink-integrate-python-code skill은 무엇을 하나요?
simulink-integrate-python-code은(는) agent skill입니다. Python Code 블록을 사용하여 일반 Python 함수, 클래스 및 라이브러리를 Simulink 모델에 통합합니다.
skill의 SKILL.md에서 생성된 요약입니다.
simulink-integrate-python-code skill 정보
이 SKILL은 R2025a 이상 버전을 사용하는 엔지니어가 일반 Python 함수, 클래스 및 라이브러리를 Simulink 모델에 통합할 수 있도록 지원합니다. 개발자는 Python Code 블록을 사용하여 시뮬레이션 내의 모든 타임스텝에서 Python 코드를 실행할 수 있습니다. 이는 모델 내부에서 numpy 또는 scipy와 같은 서드파티 라이브러리를 직접 호출해야 하거나, 시뮬레이션 단계 전반에 걸쳐 Python 객체 또는 수치 상태를 유지해야 할 때 특히 유용합니다.
사용자가 표준 MATLAB 블록으로 쉽게 처리할 수 없는 사용자 정의 Python 로직을 실행하고자 할 때 에이전트는 이 SKILL을 로드해야 합니다. py.* 호출을 사용하는 MATLAB Function 블록과 달리, Python Code 블록은 Rapid Accelerator 및 model reference Accelerator 모드를 지원합니다. 워크플로우는 모델을 생성하고 OutputCode 및 SampleTime과 같은 특정 매개변수를 가진 블록을 추가한 다음, SymbolSpec API를 통해 포트를 정의하고 마지막으로 구성 요소를 연결하는 과정을 포함합니다. 이 기능은 공유 MATLAB Python 인터프리터를 사용하며 Simulink 버스를 Python 딕셔너리로 변환하는 것을 포함한 다양한 데이터 타입 매핑을 지원합니다.
agent가 수행할 수 있는 작업
- 1시뮬레이션 내 Python 라이브러리 실행Simulink 모델 내부에서 Python 함수 또는 numpy, scipy와 같은 서드파티 라이브러리를 실행합니다.
- 2타임스텝 간 상태 유지시뮬레이션이 진행되는 동안 Python 객체 또는 수치 상태를 유지합니다.
- 3심볼을 통한 모델 포트 구성SymbolSpec API를 사용하여 범위와 데이터 타입을 설정함으로써 Python 블록의 입출력 포트를 정의합니다.
- 4고속 시뮬레이션 모드 활성화Rapid Accelerator 또는 model reference Accelerator 모드가 필요한 모델에서 Python 로직을 사용합니다.
skill의 SKILL.md를 기반으로 작성되었습니다. 모든 사용 사례는 해당 문서의 인용구와 대조 확인되었습니다.
simulink-integrate-python-code skill 설치 방법
각 명령은 skill 폴더를 클라이언트의 skills 디렉터리에 복사합니다. 클라이언트를 재시작하거나 새 세션을 시작하여 로드하세요.Claude Code에 simulink-integrate-python-code skill 설치
~/.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-codeClaude Code (project)에 simulink-integrate-python-code skill 설치
.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-codeCodex에 simulink-integrate-python-code skill 설치
~/.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-codeGemini CLI에 simulink-integrate-python-code skill 설치
~/.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-codeClaude.ai에 simulink-integrate-python-code skill 설치
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
자동 검사
2026년 11월 14일에 실행됨전체 보고서 →자동 검사를 통과했습니다. 보안 감사는 아닙니다. 에이전트가 실행하기 전에 스크립트를 읽어 보세요. 검사 방식
- 소스 저장소 연결 및 접근 가능matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code is public and reachablegithub.com/matlab/simulink-agentic-toolkit/tree/HEAD/skills- ↗통과
- 오픈 소스 라이선스 (OSI)License named in a file, not as an SPDX id검사되지 않음
- 최근 1년 내 커밋 또는 릴리스Last commit 2026-11-11github.com/matlab/simulink-agentic-toolkit/commits ↗통과
- 스크립트에 다운로드 후 실행이나 자격 증명 탈취가 없음No scripts in the skill folder통과
- SKILL.md에 숨겨진 지침 없음No override phrases, safeguard switches, credential requests or hidden charactersgithub.com/matlab/simulink-agentic-toolkit/blob/HEAD/skills- ↗통과
- 사전 허용 도구가 제한됨No pre-approved tools; the agent asks before using onegithub.com/matlab/simulink-agentic-toolkit/blob/HEAD/skills- ↗통과
SKILL.md
GitHub에서 보기Python 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.
이 스킬의 파일
5simulink-integrate-python-code skill 질문
Claude Code에 simulink-integrate-python-code skill을 어떻게 설치하나요?
npx degit matlab/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-integrate-python-code ~/.claude/skills/simulink-integrate-python-code를 실행합니다. Claude Code는 ~/.claude/skills(모든 프로젝트) 또는 .claude/skills(한 프로젝트)에서 skills를 로드하며, 설명이 작업과 일치할 때 skill을 사용합니다.
simulink-integrate-python-code skill을 사용할 수 있는 클라이언트는 무엇인가요?
Agent Skills 형식을 읽는 모든 클라이언트(Claude Code, Codex, Gemini CLI, claude.ai(ZIP으로 업로드))가 사용할 수 있습니다. skill 내 스크립트는 클라이언트가 코드 실행을 허용하는 경우에만 실행됩니다.
Python Code 블록으로 딥러닝 추론을 할 수 있나요?
아니요, PyTorch, TensorFlow 또는 ONNX와 같은 학습된 신경망 모델의 경우 Deep Learning Toolbox Model Predict 블록을 사용해야 합니다.