There has been a task that I had to deal with in the early stages after joining HERMES Team. That includes a simple hybrid schema that uses Python and Matlab to create a type of subsystem that could utilize the team's Python code in the Matlab and Simulink environment.
In general, my MATLAB required almost no modification to run Python. There are functions such as pyenv that are useful for setting up Python in MATLAB, as well as py.sys.version for checking whether the interface is working.
- USED: Display block, constants(input)/output blocks, Matlab Function Block.
1) Two inputs -> adds the numbers together -> displays the result.
2) An multiplication example with libraries (numpy) imported into Python code.
- Language: Matlab, Python (v ...)
- Modules: numpy
- Environment Simulink
| Characteristic | Detail |
|---|---|
| Inputs | No Problem with 1 / N inputs -----> 1 / M outputs. The MATLAB function block automatically recognizes the model's inputs/outputs through the code and thus adjusts what is needed. Then you just need to tweak variables/dimensions/connections, etc. |
| Python Support | Simulink may not directly support the Python language. Therefore, scripts that take blocks_of_code must be written exclusively in MATLAB functions. In other words, the code must be converted from Python => MATLAB. |
| Dimensions | Special attention must be paid to the dimensions of the variables, otherwise the model will not run. (They can be changed by clicking on function_block > Edit Data > Symbols ( & Property Inspector). |
Use the files Python Scripts for testing.
See the Licence
