How to get data from a "SimulationOutput" object from MATLAB into Python?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 10 de Nov. de 2023
Editada: MathWorks Support Team
el 25 de Abr. de 2024
I have an instance of the MATLAB Engine in Python in a variable named "eng". I am using "eng" to simulate my Simulink model by calling it from Python. I am using the following Python script to get data from the "SimulationOutput" object created at the end of the simulation in MATLAB, in Python. However, I am not able to access any variables from the "SimulationOutput" object in Python. The "out" variable seems to only be a list.
out = eng.sim('modelName)
eng.workspace['variableListedInOut']
How can I resolve this?
Respuesta aceptada
MathWorks Support Team
el 25 de Abr. de 2024
Editada: MathWorks Support Team
el 25 de Abr. de 2024
Only certain types of data types can be transferred from MATLAB to Python. For more information on how data types are mapped between MATLAB and Python, please check the documentation link below -
To actually achieve the workflow requested, you would first have to convert the "SimulationOutput" object to a struct in MATLAB and then access the data from that struct in Python. This can be achieved by using the script below
eng.eval("out=sim('model_name')",nargout=0)
eng.eval("data = struct(out)",nargout=0)
data = eng.workspace['data']
The MATLAB "struct" object that is passed to Python will automatically be converted to a Python "dict" object. This will allow you to access the SimulationObject data. See this documentation page for more information about passing data from MATLAB to Python.
https://www.mathworks.com/help/matlab/matlab_external/handle-data-returned-from-matlab-to-python.html
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!