Calling a python file from matlab/simulink
2 views (last 30 days)
Show older comments
Dear all,
I have a dataset and I have to apply different machine learning algorithms in it. Because I am more proficient in Python, I considered writing the code in Python.
Now I have a Python file that runs flawlessly and returns the predicted values. However, there is a global simulation environment in which these values must be integrated, and this global simulation environment is based on Matlab/Simulink.
I'm thinking about modeling 1D look-up tables in Simulink using the output dataset from the executed Python file. My question is, how do I get Simulink to call the Python file?
Example: A user runs the global environment model in Matlab/Simulink that calls the python file, the python files executes and saves the output in .csv format, and the look-up tables are updated and accessed in the workspace of matlab that are eventually run in Simulink.
0 Comments
Answers (1)
David Willingham
on 14 Sep 2022
Hi Rehan,
What application is the python model being used for? In simulink, do you need the model to run every time step or do you only need to run prior to the start or end of a simulation? I see you gave some use cases but it's not 100% clear.
2 Comments
David Willingham
on 15 Sep 2022
Hi Rehan,
Thanks for providing the additional context to the problem you're working on. It is very helpful to hear.
There is a post that describes how to call Python via the MATLAB function block in Simulink:
Try using this method, if you have questions please don't hesitate to reply here.
David
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!