extract py.list data in matlab to numeric

5 ビュー (過去 30 日間)
mohammad mahdi abaei
mohammad mahdi abaei 2023 年 4 月 24 日
回答済み: Luca Ferro 2023 年 4 月 24 日
Dear All,
I used [results] = pyrunfile(py_path,"x"); to extract my python simulation data into matlab. it is sucessfull done, however the type of data is py.list, then i used cell and cell2mat in order to get x array as numeric. However it always give me weeor that :
Error using cell2mat
CELL2MAT does not support cell arrays containing cell arrays or objects.
also i used double to change into numeric but i get this error:
Error using py.list/double
Conversion of Python element at position 1 to type 'double' failed. All Python elements must be convertible as scalar to the requested type.
the varibale in my python code is just a simple timeseries data, i will be thankful if you kindly help to find the solution.here is the format: val =
[array([865.18658447, 865.50640869, 865.8380127 , ..., 836.89562988,
836.19567871, 835.52642822])]
Use string, double or cell function to convert to a MATLAB array.

回答 (1 件)

Luca Ferro
Luca Ferro 2023 年 4 月 24 日
let's say that pyList is your list:
cellPyList=cell(pyList); %converts to cell array of form {[1]},{[2]},...
arrPyList=[cellPyList{:}]; %converts to numeric array of form [1,2,...]

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by