extract py.list data in matlab to numeric

8 views (last 30 days)
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.

Answers (1)

Luca Ferro
Luca Ferro on 24 Apr 2023
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,...]

Community Treasure Hunt

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

Start Hunting!