Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

%% Question 1

%part 1
I=200;
runtime=200;
starttime=10;
endtime=180;

hhcurr(I, runtime,starttime, endtime)


%part 2


runtime=200;
starttime=10;
endtime=180;
SP=[];
I=0:25:500;
for a=1:length(I);
spikerate=hhcurr(I(a), runtime,starttime, endtime)
SP=[SP, spikerate];
end

figure
plot(I, SP,'--bs','LineWidth',2)

xlabel('Magnitude of Injected Current/nA mm^2');
ylabel('Spike Rate/Hz');
title('Variation of Spike Rate with Magnitude of Injected Current')

%% hhcurr

function [spikerate]=hhcurr(IE, maxtime, tIstart, tIlength)
% Takes injected current Ie (nA/mm^2) into an integrating Hodgkin-
Huxley model
% neuron and outputs time series of Vm, m, n, h and various ionic
currents

% General neuron parameters
cm = 10; % specific membrane capacitance in nF/mm^2
r = 0.01; % neuron radius in mm

A = 4*pi*r^2; % calculate spherical neuron membrane area

% Leak, Na, and K reversal potentials (in mV)
E_L = -54;
E_K = -77;
E_Na = 50;


% HH values for [gleak, gk, gna] in mS/mm^2
gbar_L = 0.003;
gbar_K = 0.36;
gbar_Na = 1.2;

% Computer simulation parameters
dt = 0.1; % size of time step in ms
spikecounter=0;

times = 0:dt:maxtime; % create and array of time values (in ms)
nstep = length(times); % find number of time steps in integration

% Parameters of a current pulse to inject into the neuron
Ie_peak = IE * A; % injected current in nA/mm^2 (times A for total
current)


% Initialize variables to save during integration loop
m = zeros(1,nstep);
h = zeros(1,nstep);
n = zeros(1,nstep);
Vm = zeros(1,nstep); % membrane potential
Im = zeros(1,nstep); % membrane current
tau = zeros(1,nstep); % membrane time constant


% Make an array of currents Ie
nIstart = round(tIstart/dt); % time step to start pulse (nearest
integer)
nIlength = round(tIlength/dt); % length of the current pulse in time
steps
Ie = zeros(1,nstep); % initialize current
Ie(nIstart:nIstart+nIlength) = Ie_peak; % write pulse into array
Ie = Ie/1000; % convert from nA to microA


% Find initial values for HH variables
Vm(1) = -65; %initial membrane potential
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n] = hh_params(Vm(1));
m(1) = m_inf;
h(1) = h_inf;
n(1) = n_inf;


% Integration loop
for i = 1:nstep-1
% Find HH parameters for current membrane potential
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n]= hh_params(Vm(i));

% Update m, h, and n using the Exponential-Euler method
m(i+1) = m_inf+(m(i)-m_inf)*exp(-dt/tau_m);
h(i+1) = h_inf+(h(i)-h_inf)*exp(-dt/tau_h);
n(i+1) = n_inf+(n(i)-n_inf)*exp(-dt/tau_n);

% Calculate current leak, K, and Na conductances using updated m,
h, n
g_L = gbar_L;
g_K = gbar_K * n(i+1)^4;
g_Na = gbar_Na * h(i+1)*m(i+1)^3;

% Calculate updated value of V_inf
% units work out since voltage is in mV, conductance in mS/mm^2,
% current in microA, and area in mm^2
V_inf = (E_L*g_L + E_K*g_K + E_Na*g_Na + Ie(i)/A) / (g_L + g_K +
g_Na);

% Calculate updated value of the membrane time constant tau_V
% divide by 1000 to convert nF/mS = microsec to msec
tau_V = cm / (g_L + g_K + g_Na) / 1000;

% Update Vm with the Exponential-Euler Method using new V_inf and
tau_V
Vm(i+1) = V_inf+(Vm(i)-V_inf)*exp(-dt/tau_V);

if (i==1)
spikecounter = 0
else
if(Vm(i-1)<Vm(i) & Vm(i)>Vm(i+1) & Vm(i)>0) %count every peak
spikecounter = spikecounter+1
end
end
end

% Calculate currents
I_Na = A*gbar_Na*(Vm-E_Na).*h.*m.^3;
I_K = A*gbar_K*(Vm-E_K).*n.^4;

% Plot results

figure(1)



subplot(5,1,1)
plot(times,Ie/A,'-r','linewidth',1.5);
xlabel('Time (ms)');
ylabel('Ie/A');
grid on

subplot(5,1,2)
plot(times,Vm,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('Vm');
grid on

subplot(5,1,3);
plot(times,m,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('m');
grid on

subplot(5,1,4);
plot(times,h,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('h');
grid on

subplot(5,1,5);
plot(times,n,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('n');
grid on

figure(2)

subplot(5,1,2)
plot(times,Vm,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('Vm');
grid on

subplot(5,1,1)
plot(times,Ie/A,'-r','linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_e/A');
grid on

subplot(5,1,3);
plot(times,I_Na,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_N_a');
grid on

subplot(5,1,4);
plot(times,I_K,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_K');
grid on

spikerate=spikecounter/(tIlength)*1000 %calculate spike rate




%% Question 2
clear;

%%Part 1

% Provide values for parameters
Vm1 = -80;
Vm2 = -20;
maxtime = 100;
tstep1 = 20;
tstep2 = 50;
pulseL1 = 30;
pulseL2 = 30;

[Vm, I_Na, I_K, times, Imax, h_inf_empirical] = hhvolt(Vm1, Vm2,
maxtime, tstep1, pulseL1, tstep2,pulseL2);
figure(1)



subplot(2,1,1)
plot(times,Vm,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('Vm (mV)');
title('Membrane Potentials')
grid on


subplot(2,1,2);
hold on
plot(times,I_Na,'r');
plot(times,I_K,'b');
plot(times,I_K+I_Na,'--', 'linewidth', 1.5);
title('Ionic Currents')
legend('I_N_a', 'I_K', 'I_m')
xlabel('Time (ms)');
ylabel('I (nA)');
grid on





%% part 2 determining h
I=[];
Vtest=[-100:10:50];
H_inf_empirical = [];
H_inf_theoretical = [];

for a= 1:length(Vtest) % loop through different test voltages

% record peak Na current
[Vm, I_Na, I_K, times, Imax,h_inf_empirical] = hhvolt(Vtest(a),Vm2,
maxtime, tstep1, pulseL1, tstep2,pulseL2);
I=[I, Imax]

% record calculated empirical values of h_inf from the neuron model
H_inf_empirical=[H_inf_empirical, h_inf_empirical];


% calculate theoretical h_inf

alpha_h = 0.07*exp(-0.05*(Vtest(a)+65));
beta_h = 1./(1.+exp(-0.1*(Vtest(a)+35)));
tau_h = 1./(alpha_h+beta_h);
h_inf = alpha_h*tau_h;
H_inf_theoretical = [H_inf_theoretical, h_inf];

%plot current trace

figure (2)
subplot(2,1,1)
hold on
plot(times,Vm,'--');
title('Voltage Steps')
xlabel('Time (ms)');
ylabel('Vm (mV)');
grid on


subplot(2,1,2);
hold on
plot(times,I_Na,'r');
title('I_{Na`}')
xlabel('Time (ms)');
ylabel('I_{Na} (nA)');
grid on

end


% plot trends for I_Na and h


figure (3)
subplot (2,1,1)
plot (Vtest, I,'--bs','LineWidth',2)
xlabel('Test Voltage (mV)');
ylabel('I_N_a (nA)');
title('Relationship between Sodium Current and Magnitude of First
Voltage Step')


subplot (2,1,2)
hold on
plot (Vtest, H_inf_empirical,'--bs','LineWidth',2)
plot (Vtest, H_inf_theoretical,'--rs','LineWidth',2)
xlabel('Test Voltage (mV)');
ylabel('H_{inf}');
legend ('Empirical h_{inf} Values', 'Empirical h_{inf} Values')
title('Relationship between h_{inf} Value and Magnitude of First
Voltage Step')


%% Part 3 determining tau
maxtime = 105;
pulseL1 = 15;
pulseL2 = 15;

Tau=[];
Vm2=[-100:10:20]

for c=1:length(Vm2)

I=[];
tstep2=[35:5:90];
for b=1:length(tstep2)
[Vm, I_Na, I_K, times, Imax,h_inf_empirical] = hhvolt(Vm2(c),
Vm2(c), maxtime, tstep1, pulseL1, tstep2(b), pulseL2);
I=[I, Imax];
%plot the time course of Vm
figure (4)
subplot(3,1,1)
hold on
plot(times,Vm,'--');
xlabel('Time (ms)');
ylabel('Vm (mV)');
title('Membrane Potentials')
grid on
%plot the resulting Na current
subplot(3,1,2);
hold on
plot(times,I_Na,'r');
title('Na Currents')
xlabel('Time (ms)');
ylabel('I (nA)');
grid on

end

E_Na=50;
g_Na_max=I/(Vm2(c)-E_Na);

% plot variaiton of max g_Na with change of delay

subplot(3,1,3)
plot(tstep2, g_Na_max, 'o')
xlabel('Time(ms)')
ylabel('Peak g_{Na}(uS)')
xlim([0 120])

tau = -regress(g_Na_max', (log(tstep2))')
Tau = [Tau, tau]

end

figure
plot (Vm2, Tau)
xlabel ('Vm (mV)')
ylabel ('empirical tau_h(ms)')

% calculate theoretical tau_h values

alpha_h = 0.07*exp(-0.05*(Vm2+65));
beta_h = 1./(1.+exp(-0.1*(Vm2+35)));
tau_h = 1./(alpha_h+beta_h);

figure
plot (Vm2, tau_h)
xlabel ('Vm (mV)')
ylabel ('theoretical tau(ms)')




%% hhvolt


function [Vm, I_Na, I_K, times, Imax, h_inf_empirical]=hhvolt(Vm1, Vm2,
maxtime, tstep1, pulseL1, tstep2,pulseL2)
% Takes injected current Ie (nA/mm^2) into an integrating Hodgkin-
Huxley model
% neuron and outputs time series of Vm, m, n, h and various ionic
currents

% General neuron parameters
cm = 10; % specific membrane capacitance in nF/mm^2
r = 0.01; % neuron radius in mm

A = 4*pi*r^2; % calculate spherical neuron membrane area

% Leak, Na, and K reversal potentials (in mV)
E_L = -54;
E_K = -77;
E_Na = 50;
Vmr=-65;

% HH values for [gleak, gk, gna] in mS/mm^2
gbar_L = 0.003;
gbar_K = 0.36;
gbar_Na = 1.2;

% Computer simulation parameters
dt = 0.01; % size of time step in ms

times = 0:dt:maxtime; % create and array of time values (in ms)
nstep = length(times); % find number of time steps in integration



% Initialize variables to save during integration loop
m = zeros(1,nstep);
h = zeros(1,nstep);
n = zeros(1,nstep);
Vm = zeros(1,nstep); % membrane potential
Im = zeros(1,nstep); % membrane current
tau = zeros(1,nstep); % membrane time constant
H_inf=[];

% Make an array of currents Ie
nstep1 = round(tstep1/dt); % time step to start first pulse (nearest
integer)
nstep2 = round(tstep2/dt); % time step to start second pulse
npulseL1 = round(pulseL1/dt); % time step lenght of first pulse
npulseL2 = round(pulseL2/dt); % time step lenght of second pulse
Vm(1:length(Vm)) = Vmr;% set resting potential
Vm(nstep1:nstep1+npulseL1) = Vm1; % write pulse into array
Vm(nstep2:nstep2+npulseL2) = Vm2; % write pulse into array


% Find initial values for HH variables
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n] = hh_params(Vm(1));
m(1) = m_inf;
h(1) = h_inf;
n(1) = n_inf;


% Integration loop
for i = 1:nstep-1
% Find HH parameters for current membrane potential
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n]= hh_params(Vm(i));
%H_inf=[H_inf, h_inf];
% Update m, h, and n using the Exponential-Euler method
m(i+1) = m_inf+(m(i)-m_inf)*exp(-dt/tau_m);
h(i+1) = h_inf+(h(i)-h_inf)*exp(-dt/tau_h);
n(i+1) = n_inf+(n(i)-n_inf)*exp(-dt/tau_n);

% Calculate current leak, K, and Na conductances using updated m,
h, n
g_L = gbar_L;
g_K = gbar_K * n(i+1)^4;
g_Na = gbar_Na * h(i+1)*m(i+1)^3;


% Calculate updated value of the membrane time constant tau_V
% divide by 1000 to convert nF/mS = microsec to msec
tau_V = cm / (g_L + g_K + g_Na) / 1000;



end

% Calculate currents
I_Na = A*gbar_Na*(Vm-E_Na).*h.*m.^3;
I_K = A*gbar_K*(Vm-E_K).*n.^4;


%empirically measure I_Na and h
I_Na_step2=I_Na(nstep2:nstep2+npulseL2);

ind=find(I_Na_step2==min(I_Na_step2));
ind=ind+nstep2-1;

Imax=I_Na(ind); % measure the experimental I_Na peak
h_inf_empirical=Imax/A/gbar_Na/(Vm(ind)-E_Na)/1;


%% Question 3

%part 1
%inject current for 2 spikes

hhcurr(60, 400, 100, 200)

%part 2


hhcurrqn3(60, 400, 100, 200)




%for the range of Vm
Vm=[-100:5:50];


% Calculate normal h_inf
alpha_h_n = 0.07*exp(-0.05*(Vm+65));
beta_h_n = 1./(1.+exp(-0.1*(Vm+35)));
tau_h_n = 1./(alpha_h_n+beta_h_n);
h_inf_n = alpha_h_n.*tau_h_n;



% Calculate dysfunction shifted h_inf
alpha_h_s = 0.07*exp(-0.05*(Vm+60));
beta_h_s = 1./(1.+exp(-0.1*(Vm+30)));
tau_h_s = 1./(alpha_h_s+beta_h_s);
h_inf_s = alpha_h_s.*tau_h_s;

figure
hold on
plot (Vm, h_inf_n,'b')
plot (Vm, h_inf_s,'r')
xlabel('V_m (mV)')
ylabel('h_{inf} values/')


%% hhcurrqn3

function [spikerate]=hhcurr(IE, maxtime, tIstart, tIlength)
% Takes injected current Ie (nA/mm^2) into an integrating Hodgkin-
Huxley model
% neuron and outputs time series of Vm, m, n, h and various ionic
currents

% General neuron parameters
cm = 10; % specific membrane capacitance in nF/mm^2
r = 0.01; % neuron radius in mm

A = 4*pi*r^2; % calculate spherical neuron membrane area

% Leak, Na, and K reversal potentials (in mV)
E_L = -54;
E_K = -77;
E_Na = 50;


% HH values for [gleak, gk, gna] in mS/mm^2
gbar_L = 0.003;
gbar_K = 0.36;
gbar_Na = 1.2;

% Computer simulation parameters
dt = 0.1; % size of time step in ms
spikecounter=0;

times = 0:dt:maxtime; % create and array of time values (in ms)
nstep = length(times); % find number of time steps in integration

% Parameters of a current pulse to inject into the neuron
Ie_peak = IE * A; % injected current in nA/mm^2 (times A for total
current)


% Initialize variables to save during integration loop
m = zeros(1,nstep);
h = zeros(1,nstep);
n = zeros(1,nstep);
Vm = zeros(1,nstep); % membrane potential
Im = zeros(1,nstep); % membrane current
tau = zeros(1,nstep); % membrane time constant


% Make an array of currents Ie
nIstart = round(tIstart/dt); % time step to start pulse (nearest
integer)
nIlength = round(tIlength/dt); % length of the current pulse in time
steps
Ie = zeros(1,nstep); % initialize current
Ie(nIstart:nIstart+nIlength) = Ie_peak; % write pulse into array
Ie = Ie/1000; % convert from nA to microA


% Find initial values for HH variables
Vm(1) = -65; %initial membrane potential
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n] = hh_paramsqn3(Vm(1));
m(1) = m_inf;
h(1) = h_inf;
n(1) = n_inf;


% Integration loop
for i = 1:nstep-1
% Find HH parameters for current membrane potential
[m_inf, tau_m, h_inf, tau_h, n_inf, tau_n]= hh_paramsqn3(Vm(i));

% Update m, h, and n using the Exponential-Euler method
m(i+1) = m_inf+(m(i)-m_inf)*exp(-dt/tau_m);
h(i+1) = h_inf+(h(i)-h_inf)*exp(-dt/tau_h);
n(i+1) = n_inf+(n(i)-n_inf)*exp(-dt/tau_n);

% Calculate current leak, K, and Na conductances using updated m,
h, n
g_L = gbar_L;
g_K = gbar_K * n(i+1)^4;
g_Na = gbar_Na * h(i+1)*m(i+1)^3;

% Calculate updated value of V_inf
% units work out since voltage is in mV, conductance in mS/mm^2,
% current in microA, and area in mm^2
V_inf = (E_L*g_L + E_K*g_K + E_Na*g_Na + Ie(i)/A) / (g_L + g_K +
g_Na);

% Calculate updated value of the membrane time constant tau_V
% divide by 1000 to convert nF/mS = microsec to msec
tau_V = cm / (g_L + g_K + g_Na) / 1000;

% Update Vm with the Exponential-Euler Method using new V_inf and
tau_V
Vm(i+1) = V_inf+(Vm(i)-V_inf)*exp(-dt/tau_V);

if (i==1)
spikecounter = 0
else
if(Vm(i-1)<Vm(i) & Vm(i)>Vm(i+1) & Vm(i)>0) %count every peak
spikecounter = spikecounter+1
end
end
end

% Calculate currents
I_Na = A*gbar_Na*(Vm-E_Na).*h.*m.^3;
I_K = A*gbar_K*(Vm-E_K).*n.^4;

% Plot results

figure



subplot(5,1,1)
plot(times,Ie/A,'-r','linewidth',1.5);
xlabel('Time (ms)');
ylabel('Ie/A');
grid on

subplot(5,1,2)
plot(times,Vm,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('Vm');
grid on

subplot(5,1,3);
plot(times,m,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('m');
grid on

subplot(5,1,4);
plot(times,h,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('h');
grid on

subplot(5,1,5);
plot(times,n,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('n');
grid on

figure

subplot(5,1,2)
plot(times,Vm,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('Vm');
grid on

subplot(5,1,1)
plot(times,Ie/A,'-r','linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_e/A');
grid on

subplot(5,1,3);
plot(times,I_Na,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_N_a');
grid on

subplot(5,1,4);
plot(times,I_K,'linewidth',1.5);
xlabel('Time (ms)');
ylabel('I_K');
grid on

spikerate=spikecounter/(tIlength)*1000 %calculate spike rate


%% hh_paramsqn3


function [m_inf, tau_m, h_inf, tau_h, n_inf, tau_n]= hh_paramsqn3(Vm)
% HH_PARAMS Calculates the rate parameters of the Hodgkin-Huxley rate
% equations for the sodium and potassium conductances
% Na activation parameters (m_inf, tau_m)
% Na inactivation parameters (h_inf, tau_h)
% K activation parameters (n_inf, tau_n)
%
% Vm is specified in millivolts
% alpha_m, beta_m, alpha_h, beta_h, alpha_n, beta_n are in units of
1/ms
% tau_m, tau_h, tau_n are in milliseconds
% m_inf, h_inf, n_inf are unitless
%
alpha_m = (0.1*(Vm+40)+eps)/(1-exp(-0.1*(Vm+40))+eps);
beta_m = 4*exp(-0.0556*(Vm+65));
tau_m = 1./(alpha_m+beta_m);
m_inf = alpha_m*tau_m;

alpha_h = 0.07*exp(-0.05*(Vm+60));
beta_h = 1./(1.+exp(-0.1*(Vm+30)));
tau_h = 1./(alpha_h+beta_h);
h_inf = alpha_h*tau_h;

alpha_n = 0.01*(Vm+55)/(1.-exp(-0.1*(Vm+55)));
beta_n = 0.125*exp(-0.0125*(Vm+65));
tau_n = 1./(alpha_n+beta_n);
n_inf = alpha_n*tau_n;


%% Question 4
clear;

%% Part 1

Vm=[-100:2:50];
for i=1:length(Vm);

alpha_n(i) = 0.01*(Vm(i)+55)/(1.-exp(-0.1*(Vm(i)+55)));
beta_n(i) = 0.125*exp(-0.0125*(Vm(i)+65));
end

figure
hold on
plot (Vm, alpha_n, 'r')
plot (Vm, beta_n, 'b')
xlabel('Vm (mV)')
ylabel('Rate Constants ([ms]^{-1})')
legend ('alpha_n','beta_n')

Vm=-80;
alpha_n80 = 0.01*(Vm+55)/(1.-exp(-0.1*(Vm+55)))
beta_n80 = 0.125*exp(-0.0125*(Vm+65))

Vm=-40;
alpha_n40 = 0.01*(Vm+55)/(1.-exp(-0.1*(Vm+55)))
beta_n40 = 0.125*exp(-0.0125*(Vm+65))




%% Part 2


maxtime=80;
step1 = 20; % define steps by ms
step2 = 60;
step3 = 80;

dt = 0.1;
times = 0:dt:maxtime; % create and array of time values (in ms)
nstep = length(times); % find number of time steps in integration
Vm = zeros(1,nstep); % membrane potential
x= zeros(1,nstep-1);
up= zeros(1, nstep-1);
down = zeros(1, nstep-1);
x(1)=1;
xmax=5; % number of states


Vm (1:step1/dt)=-80;
Vm (step1/dt:step2/dt)=-40;
Vm (step2/dt:length(times))=-110;

figure
plot (times, Vm)
xlabel('Time (ms)')
ylabel('Vm (mV)')

% run state transitions over time
for i=1: length (Vm)

alpha_n(i) = 0.01*(Vm(i)+55)/(1.-exp(-0.1*(Vm(i)+55)))
beta_n(i) = 0.125*exp(-0.0125*(Vm(i)+65))

up(i)=dt*(xmax-x(i))*alpha_n(i)
down(i)=dt*(x(i)-1)*beta_n(i)
a=rand


if a>(1-up(i))
x(i+1)=x(i)+1
elseif a<down(i)
x(i+1)=x(i)-1
else
x(i+1)=x(i)
end

end

%plot state transition

figure
plot (times,x(1:length(times-1)))
xlabel ('Time(ms)')
ylabel ('states')



% part 3
figure
hold on
X=[];
for trial=1:10

% run state transitions over time
for i=1: length (Vm)-1

alpha_n(i) = 0.01*(Vm(i)+55)/(1.-exp(-0.1*(Vm(i)+55)));
beta_n(i) = 0.125*exp(-0.0125*(Vm(i)+65));

up(i)=dt*(xmax-x(i))*alpha_n(i);
down(i)=dt*(x(i)-1)*beta_n(i);
a=rand;


if a>(1-up(i))
x(i+1)=x(i)+1;
elseif a<down(i)
x(i+1)=x(i)-1;
else
x(i+1)=x(i);
end

if x(i)<5
x(i)=0
else
x(i)=1
end
end
X(trial, :)=x;
plot (times, (trial+0.5.*x(1:length(x)-1)))
xlabel('Time (ms)')
ylabel('Trial Number')
end

pX=sum(X)/10;
figure
plot (times, pX(1:length(pX)-1))
xlabel ('Time (ms)')
ylabel ('Probability of channel openings')


%plot for 100 channels


% part 3
figure
hold on
X=[];
for trial=1:100

% run state transitions over time
for i=1: length (Vm)-1

alpha_n(i) = 0.01*(Vm(i)+55)/(1.-exp(-0.1*(Vm(i)+55)));
beta_n(i) = 0.125*exp(-0.0125*(Vm(i)+65));

up(i)=dt*(xmax-x(i))*alpha_n(i);
down(i)=dt*(x(i)-1)*beta_n(i);
a=rand;


if a>(1-up(i))
x(i+1)=x(i)+1;
elseif a<down(i)
x(i+1)=x(i)-1;
else
x(i+1)=x(i);
end

if x(i)<5
x(i)=0
else
x(i)=1
end
end
X(trial, :)=x;
plot (times, (trial+0.5.*x(1:length(x)-1)))
xlabel('Time (ms)')
ylabel('Trial Number')
end

pX=sum(X)/100;
figure
plot (times, pX(1:length(pX)-1))
xlabel ('Time (ms)')
ylabel ('Probability of channel openings')

0 10 20 30 40 50 60 70 80
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Time (ms)
P
r
o
b
a
b
i
l
i
t
y

o
f

c
h
a
n
n
e
l

o
p
e
n
i
n
g
s

You might also like