Use the code written in PYTHON in MATLAB/Simulink R2015b
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
atharva
le 7 Déc 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!