extract py.list data in matlab to numeric
8 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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,...]
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!