extract py.list data in matlab to numeric

8 Ansichten (letzte 30 Tage)
mohammad mahdi abaei
mohammad mahdi abaei am 24 Apr. 2023
Beantwortet: Luca Ferro am 24 Apr. 2023
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.

Antworten (1)

Luca Ferro
Luca Ferro am 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,...]

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by