How to convert a 1x5x5600 cell in MATLAB to a python list that is (1,5,5600)
5 次查看(过去 30 天)
显示 更早的评论
I have a cell in MATLAB is 1x5x5600 and I need to convert it so I can use it in python and it would be easiest if it were in a list that is dimensions (1,5,5600)
1 个评论
回答(1 个)
Al Danial
2022-8-5
Lists, like cell arrays, may be nested so @J C's request is doable. Here's an example with a 1x3x5 cell:
% create the cell array
a = cell(1,3,5);
for r = 1:3
for c = 1:5
a{1,r,c} = r*1000 + c;
end
end
% convert it to an equivalent, similarly shaped Python list
py_a = py.list();
py_a_level1 = py.list();
for r = 1:3
py_a_level2 = py.list();
for c = 1:5
py_a_level2.append( a{1,r,c} );
end
py_a_level1.append( py_a_level2 );
end
py_a.append( py_a_level1 );
In Python, py_a looks like this:
In : py_a
Out:
[[[1001.0, 1002.0, 1003.0, 1004.0, 1005.0],
[2001.0, 2002.0, 2003.0, 2004.0, 2005.0],
[3001.0, 3002.0, 3003.0, 3004.0, 3005.0]]]
In : py_a[0][1][2]
Out: 2003.0
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!