0

As part of a larger project, I'm trying to convert a MATLAB model to python, but there's a single part I'm having trouble figuring out:

f%% Parameters of the model: 1=K,R  2=Ca,T  3=KCa,H  4=Na
g(1)=26; g(2)=2.25; g(3)=9.5; g(4)=1;
E(1)=-.95; E(2)=1.20; E(3)=E(1); E(4)=.50;

%% Initial values
dt=.01; I_ext=0; V=-1; x=zeros(1,4);
tau(1)=dt./4.2; tau(2)=dt./14; tau(3)=dt./45; tau(4)=1;

%% Integration
t_rec=0;
% This is the loop I am confused about:
for t=-100:dt:200
    switch t;
        case 0; I_ext=1;
    end
% until here.    
    x0(1)=1.24  +  3.7*V + 3.2*V^2;
    x0(2)=4.205 + 11.6*V + 8  *V^2;
    x0(3)=3*x(2);
    x0(4)=17.8  + 47.6*V +33.8*V^2;

    x=x-tau.*(x-x0); %rem x(4)=x0(4) because tau(4)=1
    I=g.*x.*(V-E);
    V=V+dt*(I_ext-sum(I));

%and this loop:    
    if t>=0;
        t_rec=t_rec+1;
        x_plot(t_rec)=t;
        y_plot(t_rec)=V;
    end
end % time loop
%until here.

How would I python-ify this?

Sartorible
  • 338
  • 1
  • 2
  • 11
  • 1
    Why is this a switch statement rather than `if t == 0`? – Suever Mar 04 '16 at 21:07
  • @Suever For the same reason that the loop over `t` includes values other than `0`: This is not the complete code, rather an attempt at providing a minimal example. (Now watch the OP prove me wrong...) ;) – beaker Mar 04 '16 at 21:11
  • @beaker I realize that, but then this is a poor (overly minimal) example demonstrating what functionality is required. – Suever Mar 04 '16 at 21:12
  • Sorry folks, I missed a little bit of code out. I'll edit the question. – Sartorible Mar 04 '16 at 21:15
  • @FindingIKK Does your switch statement literally only have one case? – Suever Mar 04 '16 at 21:26
  • @Sever That's how the code was provided by a colleague. I have no experience with matlab. – Sartorible Mar 04 '16 at 21:29

1 Answers1

2

A switch statement with only one case is called an if statement

if t == 0:
    I_ext = 1
Suever
  • 64,497
  • 14
  • 82
  • 101