How to Use Python Code in Simulink @MATLAB
How to Use Python Code in Simulink  @MATLAB
Uploaded September 2026 | Updated November 2026, 2 days ago
Have Python® code you want to use in Simulink®? In this demonstration, you’ll learn how to integrate native Python code directly into a Simulink model using the Python Code block.

Explore the entire process, including setting up your environment, importing a module, defining inputs and outputs, and executing code at each simulation step. You’ll also see how stateful logic—such as a filter that depends on previous inputs and outputs—can be incorporated into a model without rewriting the original implementation.

By the end of the demonstration, you will know how to combine existing Python algorithms or libraries with system-level modeling and simulation in only a few steps.

Learn more:
- Access the example shown in this video: bit.ly/4pHzf3L
- Configure your system to use Python: bit.ly/4pIzETA
- Explore the Python Code block documentation: bit.ly/45tI0Fm
- Python in Simulink documentation: bit.ly/4fG9bBw
- Python in MATLAB documentation: bit.ly/3rKn4nA

Chapters:
0:00 Introduction
0:26 The Python code
0:42 Configure the environment
1:16 The Simulink model
1:54 Understand and configure the Python Code block
4:00 Run the simulation
4:14 Conclusion

--------------------------------------------------------------------------------------------------------
Get a free product trial: goo.gl/ZHFb5u
Learn more about MATLAB: goo.gl/8QV7ZZ
Learn more about Simulink: goo.gl/nqnbLe
See what's new in MATLAB and Simulink: goo.gl/pgGtod

© 2026 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc.
See mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
How to Use Python Code in SimulinkCustomizing Lanes in RoadRunner | RoadRunner Tutorial, Part 5Using SIR Epidemic Modeling and Control to Teach Process Dynamics and Control to Chemical EngineersUnderstanding and Processing Point Clouds | Deep Learning for 3D Object Detection, Part 1What Is Time Series Modeling?What Are Bode Plots?Convert Specialized Power Systems (SPS) models to Simscape Electrical modelsIntroduction to Variant Subsystems in SimulinkWhat Is Econometrics Toolbox?Modeling Time Delays in MATLABIntroducing Simulink Copilot and Generative AI for Model-Based DesignHow to Explore Wireless Signals Using MATLAB and Software Defined Radio
MATLAB |

How to Use Python Code in Simulink

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER