- Write the instantaneous value of signal in a workspace variable using toworkspace block.
- Using matlabengine api from python read that variable.
What's the fastest way to send out data from Simulink during simulation?
6 views (last 30 days)
Hello everyone, I'm looking for the fastest way to send out Simulink data to Python during simulation. As a way of sampling the simulation in a "real time" manner.
I've tried MQTT publishing with Industrial Communication Toolbox but the delay is 0.5s on average (which is too much for my application, RL training). Also running the get_param command from Python takes about 0.3s.
Is there a way to obtain a signal's data "on the go" with minimal delay from Simulink to Python? Even if data is lost from time to time. I'm interested in speed more than security level.
Vijay on 26 Dec 2022
Edited: Vijay on 26 Dec 2022
Hello @Enzo Yacometti
Data is passed by value from MATLAB to python so, if your data is large, it will take time. However, you mentioned you need to sample a signal from SIMULINK.
You can do the following
eng = matlab.engine.connect_matlab();
Val = eng.workspace[‘instantaneousSinglaValue’];
#do soemthing with val
Use the link for further information
2. Connect shared MATLAB session to MATLAB Engine for Python - MATLAB matlab.engine.connect_matlab - MathWorks India
Hope that helps!