Skip to content

Commit fbad80a

Browse files
committed
preserve shape of 2D cell arrays
1 parent 6058be6 commit fbad80a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

code/matlab_py/mat2py.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,26 @@
100100
end
101101
case 'cell'
102102
x_py = py.list();
103-
for i = 1:numel(x_mat)
104-
x_py.append(mat2py(x_mat{i}, char_to));
103+
dims = size(x_mat);
104+
if prod(dims) == max(size(x_mat))
105+
% 1D cell array
106+
for i = 1:numel(x_mat)
107+
x_py.append(mat2py(x_mat{i}, char_to));
108+
end
109+
else
110+
if length(dims) > 2
111+
fprintf('mat2py: %d-dimensional cell array conversion ' + ...
112+
'is not implemented\n', length(dims));
113+
return
114+
end
115+
nR = dims(1,1); nC = dims(1,2);
116+
for r = 1:nR
117+
this_row = py.list();
118+
for c = 1:nC
119+
this_row.append(mat2py(x_mat{r,c}, char_to));
120+
end
121+
x_py.append(this_row);
122+
end
105123
end
106124
case 'struct'
107125
x_py = py.dict();

0 commit comments

Comments
 (0)