How to get data from a "SimulationOutput" object from MATLAB into Python?
조회 수: 10 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2023년 11월 10일
편집: MathWorks Support Team
2024년 4월 25일
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?
채택된 답변
MathWorks Support Team
2024년 4월 25일
편집: MathWorks Support Team
2024년 4월 25일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!