Need help constructing plots for a variable vector

1 view (last 30 days)
Construct plots of membrane voltage, ion channel currents and state variables for gbarK = 32, 18, 9, 3, 2 and 0 mS/cm2 as a function of time (0 – 40 msec).
I have tried to change the variable single value to just a vector but i get an error. I also would like to have each plot with each value change all on the same graphs.
I get this error when i try using the gbarK variable as a vector.
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in HHprojectpart2>HH (line 94)
dydt = [((1/Cm)*(I-(INa+IK+Il))); an(V)*(1-n)-bn(V)*n; am(V)*(1-m)-bm(V)*m;
ah(V)*(1-h)-bh(V)*h];
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in HHprojectpart2 (line 17)
[time,V] = ode45(@HH,tspan,y0,options)
clc;
dt=0.05; % Time Step ms
t=0:dt:40; %Time Array ms
V=0; % Initial Membrane voltage
ENa=115; % mv Na potential
EK=-12; % mv K potential
El=10.6; % mv Leakage potential
gbarNa=120; % mS/cm^2 Na conductance
gbarK=[32 18 9 3 2 0]; % mS/cm^2 K conductance
gbarl=0.3; % mS/cm^2 Leakage conductance
m=am(V)/(am(V)+bm(V)); % Initial m value
n=an(V)/(an(V)+bn(V)); % Initial n value
h=ah(V)/(ah(V)+bh(V)); % Initial h value
y0=[V;n;m;h]; %Initial value vector
tspan = [0,max(t)]; %Time vector
options=odeset('RelTol',1e-5);
[time,V] = ode45(@HH,tspan,y0,options);
%Variables for the vectors dV/dt, n, m, h, to graph each
OD=V(:,1);
ODn=V(:,2);
ODm=V(:,3);
ODh=V(:,4);
%Equations for currents of K and Na over time
gNa=gbarNa*ODm.^3.*ODh;
gK=gbarK.*ODn.^4;
INa=gNa.*(OD-ENa);
IK=gK.*(OD-EK);
%Time constants as a function of potential
Vr=-100:1:100; %Range for the potential
taum=1./(amr(Vr)+bmr(Vr)); %Time constant for m gate
tauh=1./(ahr(Vr)+bhr(Vr)); %Time constant for h gate
taun=1./(anr(Vr)+bnr(Vr)); %Time constant for n gate
%steady state activation and inactivation as a function of potential
mss=amr(Vr)./(amr(Vr)+bmr(Vr)); %Steady state m gate
hss=ahr(Vr)./(ahr(Vr)+bhr(Vr)); %Steady state h gate
nss=anr(Vr)./(anr(Vr)+bnr(Vr)); %Steady state n gate
%Plots
plot(time,OD);
xlabel('Time (ms)');
ylabel('Voltage (mV)');
title('Voltage change over time');
figure
plot(time,IK,'b',time,INa,'g');
xlabel('Time (ms)');
ylabel('Current (microA)');
title('Potassium and Sodium Currents over time');
legend('IK', 'INa');
%figure
%plot(time,ODm,'b',time,ODh,'g',time,ODn,'r');
%xlabel('Time (ms)');
%ylabel('Activation and inactivation variables')
%title('Activation and inactivation m, h, n, over time');
%legend('m', 'h', 'n');
%figure
%plot(Vr,taum,'b',Vr,tauh,'g',Vr,taun,'r');
%xlabel('Voltage (mV)');
%ylabel('Activation and inactivation time constants (msec)')
%title('Time constants m, h, n, as a function of potential');
%legend('tau m','tau h','tau n');
figure
plot(Vr,mss,'b',Vr,hss,'g',Vr,nss,'r');
xlabel('Voltage (mV)');
ylabel('Steady state activation and inactivation variables');
title('Steady state m, h, n, as a function of potential');
legend('mss','hss','nss');
function dydt = HH(t,y)
% Constants
ENa=115; % mv Na potential
EK=-12; % mv K potential
El=10.6; % mv Leakage potential
gbarNa=120; % mS/cm^2 Na conductance
gbarK=[32 18 9 3 2 0]; % mS/cm^2 K conductance
gbarl=0.3; % mS/cm^2 Leakage conductance
%Applied Current
if t>=0.5 && t<=0.55
I=200; %microA/cm^2
else
I=0;
end
Cm = 1; %Membrane Capacitance
% Values set to equal input values
V = y(1);
n = y(2);
m = y(3);
h = y(4);
gNa=gbarNa*m^3*h;
gK=gbarK.*n^4;
gl=gbarl;
INa=gNa*(V-ENa);
IK=gK*(V-EK);
Il=gl*(V-El);
%Hodgkin-Huxley Model Equation
dydt = [((1/Cm)*(I-(INa+IK+Il))); an(V)*(1-n)-bn(V)*n; am(V)*(1-m)-bm(V)*m; ah(V)*(1-h)-bh(V)*h];
end
function a=am(V) %Alpha for Variable m
a=((25-V)/10)/(-1+exp((25-V)/10));
end
function b=bm(V) %Beta for variable m
b=4*exp(-(V)/18);
end
function a=an(V)%Alpha for variable n
a=((9.5-V)/100)/(-1+exp((9.5-V)/10));
end
function b=bn(V) %Beta for variable n
b=0.125*exp(-(V)/80);
end
function a=ah(V) %Alpha value for variable h
a=0.07*exp(-(V)/20);
end
function b=bh(V) %Beta value for variable h
b=1/(1+exp((30-V)/10));
end
function a=amr(Vr) %Alpha potential for Variable m
a=((25-Vr)/10)./(-1+exp((25-Vr)/10));
end
function b=bmr(Vr) %Beta potential for variable m
b=4*exp(-(Vr)/18);
end
function a=ahr(Vr) %Alpha potential value for variable h
a=0.07*exp(-(Vr)/20);
end
function b=bhr(Vr) %Beta potential for variable h
b=1./(1+exp((30-Vr)/10));
end
function a=anr(Vr) %Alpha potential value for variable n
a=((9.5-Vr)/100)./(-1+exp((9.5-Vr)/10));
end
function b=bnr(Vr) %Beta potential for variable n
b=0.125*exp(-(Vr)/80);
end
  2 Comments
Image Analyst
Image Analyst on 8 Dec 2020
What exactly did you try to change to a vector? And you forgot to post the error message. We need ALL the red text, not just some of it.
silent
silent on 8 Dec 2020
i changed the gbarK variable i had as a single value to a vector of multiple values. I posted the full error messages that popped up.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!