Skip to content

xAsmodeus/Matlab-Function-Block-Python-Integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

110 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matlab Function Block Python Integration


📑 Table of Contents


🧭 Overview

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.

Screenshot_1


🛠️ Approach

  • USED: Display block, constants(input)/output blocks, Matlab Function Block.

1) Two inputs -> adds the numbers together -> displays the result.

image

2) An multiplication example with libraries (numpy) imported into Python code.

image

⚙️ Installation

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.


🧰 Technology Stack

  • Languages: Matlab, Python 3
  • Modules: numpy
  • Environments Matlab, Simulink

👀 Observations

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).

🧪 Test Files

Use the files Python Scripts for testing.


🛡️ Licence

MIT License


🙌 Credits

Sources
Python Scripts were given from Giannoulas Giannis
https://chatgpt.com

About

Hybrid Matlab-Simulink-Python project that integrates Python code into Matlab Function Blocks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages