Skip to content

Commit ec02f24

Browse files
committed
handle struct, logical; fix loop bounds on cell
1 parent f51d4a1 commit ec02f24

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

code/matlab_py/mat2py.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,23 @@
9090
x_py = np.array(real(x_mat)) + 1j*np.array(imag(x_mat));
9191
end
9292
end
93+
case 'logical'
94+
if x_mat
95+
x_py = py.True;
96+
else
97+
x_py = py.False;
98+
end
9399
case 'cell'
94100
x_py = py.list();
95-
for i = numel(x_mat)
101+
for i = 1:numel(x_mat)
96102
x_py.append(mat2py(x_mat{i}, char_to));
97103
end
104+
case 'struct'
105+
x_py = py.dict();
106+
F = fieldnames(x_mat);
107+
for i = 1:length(F)
108+
x_py.update(pyargs(F{i}, mat2py(x_mat.(F{i}))));
109+
end
98110
otherwise
99111
fprintf('mat2py: %s conversion is not implemented\n', class(x_mat))
100112
end % switch

0 commit comments

Comments
 (0)