필터 지우기
필터 지우기

extract py.list data in matlab to numeric

조회 수: 9 (최근 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 CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by