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!