Use the code written in PYTHON in MATLAB/Simulink R2015b

4 次查看(过去 30 天)
I am using MATLAB/Simulink version R2015b. Is it possible to incorporate and use code written in Python in a model of MATLAB/Simulink version R2015b? What kind of methods should I do?

回答(2 个)

atharva
atharva 2023-12-7
Hey 猛,
I understand that you want to know how to incorporate and use code written in Python in a model of MATLAB/Simulink version R2015b
You can run a Python script from MATLAB using the "system" function. For example, if your Python script was named "file.py", you could run it from MATLAB using the following command:
>> system('python file.py')
See this MATLAB answers post for more information on this workflow.
However, running a Python script from Simulink is not officially supported. MATLAB code can be executed by a Simulink model, but this typically requires the MATLAB code to be supported for code generation, even if you are just simulating the Simulink model. The "system" function is not supported for code generation.
The best potential workaround would be to write a MATLAB function that uses the "system" command, and then use an Interpreted MATLAB Function block to run this MATLAB function in your Simulink model. If this method works, you will not be able to generate code for your model, and the model will likely simulate very slowly. If this method does not work, the best workaround would be to implement the functionality of your Simulink model in MATLAB instead of Simulink, since MATLAB does officially integrate with Python scripts.
You can look at the following documentation to have a better idea-
I hope this helps!

猛
2023-12-10
Hi atharva,
Thank you very much. This is very useful advice for me. I will give it a try.

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

标签

产品


版本

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by