MATLAB Answers

How to run a python code on simulink?

280 views (last 30 days)
I am trying do some image processing and have codes written in python. I am trying to make it run on matlab/simulink. Is there a simulink block that can run python codes? Something like I can give an input to the block, it will run the python code and give the output.


Sign in to comment.

Accepted Answer

Nick Choi
Nick Choi on 6 Oct 2017
You could try using a MATLAB function block that contains MATLAB code to call the Python code.
This documentation link provides an example of how to integrate a MATLAB function block into a Simulink model,
and this documentation link contains useful information on how to use Python code with MATLAB:
One thing to note is that not all MATLAB functionalities will be supported for code generation so you may need to use 'coder.extrinsic' in the MATLAB function block. Additional information on 'coder.extrinsic' can be found here:


Bikash Sah
Bikash Sah on 22 May 2018
Can you please share a sample model that links Python with Simulink. I tried multiple times, but I was not able to.
Henry Kotze
Henry Kotze on 19 Mar 2019
What you need to do is: Create a matlab function (Not a simulink Matlab Function block) where you call your Python script. Remember to convert them to the correct types and ensure that the matlab function is able to see the python script.
Then from simulink you use the Interpreted Matlab Function block in simulink to call your function.

Sign in to comment.

More Answers (0)

Sign in to answer this question.