convert matlab code python