443,846 Members | 1,862 Online Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

# How to translate matlab to python

 P: 5 Hi, I am trying to translate a simple program that was written in matlab to python. I uses arrays to plot multiple data in single graph. I wrote the python according to the matlab language. But is seems like i made some mistake along the way. Please help me Thank you in advance This is matlab code that actually works Expand|Select|Wrap|Line Numbers subplot(5,4,1)   a=0.02; b=0.2;  c=-65;  d=6;  V=-70;  u=b*V;  VV=[];  uu=[];  tau = 0.25; tspan = 0:tau:100;  T1=tspan(end)/10;  for t=tspan      if (t>T1)           I=14;      else          I=0;      end;      V = V + tau*(0.04*V^2+5*V+140-u+I);      u = u + tau*a*(b*V-u);      if V > 30          VV(end+1)=30;          V = c;          u = u + d;      else          VV(end+1)=V;      end;      uu(end+1)=u;  end;  plot(tspan,VV,[0 T1 T1 max(tspan)],-90+[0 0 10 10]);  axis([0 max(tspan) -90 30])  axis off;  title('(A) tonic spiking');    This is my python code. Expand|Select|Wrap|Line Numbers import sys  from math import *  from scipy.integrate import odeint # ODE integration  from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas  from matplotlib.figure import Figure  import numpy  import pylab    a = 0.02  b = 0.2  c = -65  d = 6  V = -70  u = b * V  VV = []  uu = []  tau = 0.25  tspan = numpy.arange(0,101,tau)  T1 = tspan(-1)/10    for t in tspan:      if t>T1:          I = 14      else:           I = 0      V = V + tau*(0.04*V^2+5*V+140-u+I)      u = u + tau*a*(b*V-u)      if V>30:          VV[end+1]=30          V = c          u = u + d      else:          VV[end+1] = V      uu[end+1] = u  pylab.plot(tspan,VV)  pylab.show()      Oct 19 '10 #1 