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?
0 个评论
回答(2 个)
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')
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!