473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Please help me translate matlab to python

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
  1. subplot(5,4,1) 
  2. a=0.02; b=0.2;  c=-65;  d=6;
  3. V=-70;  u=b*V;
  4. VV=[];  uu=[];
  5. tau = 0.25; tspan = 0:tau:100;
  6. T1=tspan(end)/10;
  7. for t=tspan
  8.     if (t>T1) 
  9.         I=14;
  10.     else
  11.         I=0;
  12.     end;
  13.     V = V + tau*(0.04*V^2+5*V+140-u+I);
  14.     u = u + tau*a*(b*V-u);
  15.     if V > 30
  16.         VV(end+1)=30;
  17.         V = c;
  18.         u = u + d;
  19.     else
  20.         VV(end+1)=V;
  21.     end;
  22.     uu(end+1)=u;
  23. end;
  24. plot(tspan,VV,[0 T1 T1 max(tspan)],-90+[0 0 10 10]);
  25. axis([0 max(tspan) -90 30])
  26. axis off;
  27. title('(A) tonic spiking');
  28.  
This is my python code.
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. from math import *
  3. from scipy.integrate import odeint # ODE integration
  4. from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
  5. from matplotlib.figure import Figure
  6. import numpy
  7. import pylab
  8.  
  9. a = 0.02
  10. b = 0.2
  11. c = -65
  12. d = 6
  13. V = -70
  14. u = b * V
  15. VV = []
  16. uu = []
  17. tau = 0.25
  18. tspan = numpy.arange(0,101,tau)
  19. T1 = tspan(-1)/10
  20.  
  21. for t in tspan:
  22.     if t>T1:
  23.         I = 14
  24.     else: 
  25.         I = 0
  26.     V = V + tau*(0.04*V^2+5*V+140-u+I)
  27.     u = u + tau*a*(b*V-u)
  28.     if V>30:
  29.         VV[end+1]=30
  30.         V = c
  31.         u = u + d
  32.     else:
  33.         VV[end+1] = V
  34.     uu[end+1] = u
  35. pylab.plot(tspan,VV)
  36. pylab.show()
  37.  
  38.  
Oct 15 '10 #1
0 1165

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: yy0127 | last post by:
I don't know why i entered the below code and it will miss some records. Anyone can help me??? users = {} users1 = {} while 1: user, serviceType, msgType, inOut, date, time, numBytes =
22
by: Ray | last post by:
Hello, I've been learning Python in my sparetime. I'm a Java/C++ programmer by trade. So I've been reading about Python OO, and I have a few questions that I haven't found the answers for :) ...
3
by: Mike | last post by:
public class Broadcaster: MarshalByRefObject, IBroadcaster { public event General.MessageArrivedHandler MessageArrived; public void BroadcastMessage(string msg) { Console.WriteLine("Will...
9
by: lskov | last post by:
Does sombody in here know how i can set an wariable in matlab from python. I have found numpy an pymat, but i can not find out how to use it. Im using python 2.5 and matlab 2006b.
7
by: =?Utf-8?B?QWxleGFuZGVy?= | last post by:
Hi! I want to learn C# in the near future. But for now, I would be more than happy if someone could translate this short c# source code into c++. (I searched the web for c++ equivalents but after...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.