Why do I receive an error when running this code?

2 visualizaciones (últimos 30 días)
Alexis Robinson
Alexis Robinson el 12 de Oct. de 2022
Respondida: David Hill el 13 de Oct. de 2022
I keep getting an error next to my Jk and IL under 2). I am unsure how to fix it.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Template for Hodgkin Huxley model of action potential
% in a giant squid axon
% Complete the code by inserting appropriate expressions
% in the places marked
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define constants here
Vrest = -60 ; % resting potential, mV
ENa = 52.4 ; % sodium Nernst potential, mV
gNa_max = 120 ; % sodium saturation conductance, mS/cm2
Cm = 1 ; % membrane capacitance, uF/cm^2
1) Define other constant related to IK and IL here
% Define other constants related to IK and IL here
Ek = -72.1 ; % potassium Nernst potential, mV
EL = -49.2 ; % leak Nernst potential, mV
% time stepping and stimulus related constants
deltaT = 0.01 ; % time step, millisec
tStart = -1.000 ; % start time, millisec
tEnd = 15.000 ; % end time, millisec
nStep = ceil((tEnd-tStart)/deltaT) ; % number of time steps
outputInterval = 20 ; % number of time steps between screen output
StimDur=2; % duration of the stimulus, millisec
Jstim=150; % strength of stimulus
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set initial value of state variables
Vm = Vrest ; % membrane potential, mV
m = 0.05293 ; % initial value of m gate
2) similarly, declare initial values of h and n gates here
h = 0.59612 ; % h gate value
n = 0.31768 ; % n gate value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Storage for variables to plot
plot_Vm = zeros(nStep,1) ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Print a heading for the screen output
disp('Hodgkin-Huxley squid axon model')
fprintf('\t Time \t Vm \t n \t\t m \t\t h\n');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start the simulation
tNow = tStart ;
for iStep = 1:nStep
% Compute ion currents & stimulus current
JNa = gNa_max*m*m*m*h*(Vm-ENa) ;
Jk = gk_max*m*m*m*H*(Vm-Ek) ;
IL = gL_max*m*m*m*H*(Vm-EL) ;
3) write similar expressions for JK and IL here
if( 0<=tNow && tNow<StimDur ) % apply stimulus current at t=0
Jm = Jstim ;
else
Jm = 0 ;
end
% Compute gates' opening and closing rates
alpha_m = 0.1*(25-Vm)/(exp(0.1*(25-Vm))-1);
beta_m = 4*exp(-Vm/18);
m = m + deltaT*(alpha_m*(1-m)-beta_m*m);
4) Write similar expressions for n and h gates here
alpha_n = 0.1*(10-Vm)/(exp(0.1*(10-Vm))-1);
beta_n = 0.125*exp(-Vm/80);
n = n + deltaT*(alpha_n*(1-n)-beta_n*n);
alpha_h = 0.07*exp(-Vm/20);
beta_h = (exp((30-Vm)/10)+1)^-1;
h = h + deltaT*(alpha_h*(1-h)-beta_h*h);
% Compute change in state variables
deltaVm = -deltaT * (JNa + JK + JL - Jm)/Cm ;
% Record/display state variables & other values
plot_Vm(iStep) = Vm ;
plot_time(iStep) = tNow ;
if mod(iStep,outputInterval) == 0
fprintf('%8.2f %7.3f %7.5f %7.5f %7.5f\n', ...
tNow, Vm, n, m, h) ;
end % if mod(tNow)
% Update state variables
Vm = Vm + deltaVm ; % new Vm = current Vm + change in Vm
tNow = tStart + iStep*deltaT ; % increment the time
end % for iStep
% Plot the gates, probabilities, currents, Vm, etc
plot(plot_time, plot_Vm); grid on ;
5) Similarly plot gates n, m and h against time
end of file
  1 comentario
Cris LaPierre
Cris LaPierre el 13 de Oct. de 2022
Consider sharing the complete error message (all the red text).

Iniciar sesión para comentar.

Respuestas (1)

David Hill
David Hill el 13 de Oct. de 2022
You have not defined several variables: gk_max, gL_max, H, JK, JL. Once you define these variable the code will run.
gk_max=1;gL_max=1;H=1;JK=1;JL=1; %you need to define these variables.
Vrest = -60 ; % resting potential, mV
ENa = 52.4 ; % sodium Nernst potential, mV
gNa_max = 120 ; % sodium saturation conductance, mS/cm2
Cm = 1 ; % membrane capacitance, uF/cm^2
% Define other constants related to IK and IL here
Ek = -72.1 ; % potassium Nernst potential, mV
EL = -49.2 ; % leak Nernst potential, mV
% time stepping and stimulus related constants
deltaT = 0.01 ; % time step, millisec
tStart = -1.000 ; % start time, millisec
tEnd = 15.000 ; % end time, millisec
nStep = ceil((tEnd-tStart)/deltaT) ; % number of time steps
outputInterval = 20 ; % number of time steps between screen output
StimDur=2; % duration of the stimulus, millisec
Jstim=150; % strength of stimulus
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set initial value of state variables
Vm = Vrest ; % membrane potential, mV
m = 0.05293 ; % initial value of m gate
h = 0.59612 ; % h gate value
n = 0.31768 ; % n gate value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Storage for variables to plot
plot_Vm = zeros(nStep,1) ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Print a heading for the screen output
disp('Hodgkin-Huxley squid axon model')
Hodgkin-Huxley squid axon model
fprintf('\t Time \t Vm \t n \t\t m \t\t h\n');
Time Vm n m h
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start the simulation
tNow = tStart ;
for iStep = 1:nStep
% Compute ion currents & stimulus current
JNa = gNa_max*m*m*m*h*(Vm-ENa) ;
Jk = gk_max*m*m*m*H*(Vm-Ek) ;
IL = gL_max*m*m*m*H*(Vm-EL) ;
if( 0<=tNow && tNow<StimDur ) % apply stimulus current at t=0
Jm = Jstim ;
else
Jm = 0 ;
end
% Compute gates' opening and closing rates
alpha_m = 0.1*(25-Vm)/(exp(0.1*(25-Vm))-1);
beta_m = 4*exp(-Vm/18);
m = m + deltaT*(alpha_m*(1-m)-beta_m*m);
alpha_n = 0.1*(10-Vm)/(exp(0.1*(10-Vm))-1);
beta_n = 0.125*exp(-Vm/80);
n = n + deltaT*(alpha_n*(1-n)-beta_n*n);
alpha_h = 0.07*exp(-Vm/20);
beta_h = (exp((30-Vm)/10)+1)^-1;
h = h + deltaT*(alpha_h*(1-h)-beta_h*h);
% Compute change in state variables
deltaVm = -deltaT * (JNa + JK + JL - Jm)/Cm ;
% Record/display state variables & other values
plot_Vm(iStep) = Vm ;
plot_time(iStep) = tNow ;
if mod(iStep,outputInterval) == 0
fprintf('%8.2f %7.3f %7.5f %7.5f %7.5f\n', ...
tNow, Vm, n, m, h) ;
end % if mod(tNow)
% Update state variables
Vm = Vm + deltaVm ; % new Vm = current Vm + change in Vm
tNow = tStart + iStep*deltaT ; % increment the time
end % for iStep
-0.81 -60.368 0.30209 0.00001 0.69649 -0.61 -60.768 0.28723 0.00001 0.77324 -0.41 -61.168 0.27305 0.00001 0.83157 -0.21 -61.568 0.25953 0.00001 0.87565 -0.01 -61.968 0.24664 0.00001 0.90876 0.19 -33.868 0.23893 0.00043 0.92284 0.39 -4.268 0.26219 0.00956 0.92372 0.59 25.395 0.40576 0.09451 0.89478 0.79 56.027 0.69205 0.39465 0.77357 0.99 59.423 0.88685 0.70483 0.63841 1.19 56.566 0.95011 0.83219 0.52891 1.39 56.342 0.97303 0.89141 0.43886 1.59 56.642 0.98174 0.92100 0.36423 1.79 57.214 0.98518 0.93666 0.30225 1.99 57.995 0.98665 0.94575 0.25072 2.19 52.346 0.98597 0.94063 0.20943 2.39 52.291 0.98544 0.93576 0.17545 2.59 52.270 0.98522 0.93312 0.14713 2.79 52.245 0.98513 0.93167 0.12355 2.99 52.218 0.98508 0.93083 0.10390 3.19 52.186 0.98505 0.93031 0.08754 3.39 52.149 0.98503 0.92994 0.07390 3.59 52.108 0.98501 0.92964 0.06255 3.79 52.061 0.98498 0.92937 0.05309 3.99 52.008 0.98496 0.92909 0.04521 4.19 51.949 0.98493 0.92879 0.03865 4.39 51.884 0.98490 0.92847 0.03318 4.59 51.812 0.98487 0.92811 0.02863 4.79 51.735 0.98483 0.92772 0.02485 4.99 51.651 0.98479 0.92729 0.02170 5.19 51.561 0.98475 0.92683 0.01907 5.39 51.467 0.98470 0.92633 0.01689 5.59 51.367 0.98465 0.92580 0.01508 5.79 51.264 0.98460 0.92523 0.01358 5.99 51.157 0.98455 0.92463 0.01233 6.19 51.048 0.98449 0.92401 0.01130 6.39 50.938 0.98443 0.92337 0.01044 6.59 50.828 0.98437 0.92271 0.00973 6.79 50.718 0.98431 0.92204 0.00915 6.99 50.609 0.98425 0.92136 0.00867 7.19 50.502 0.98419 0.92068 0.00828 7.39 50.399 0.98413 0.92001 0.00795 7.59 50.298 0.98408 0.91935 0.00769 7.79 50.202 0.98402 0.91870 0.00748 7.99 50.111 0.98397 0.91807 0.00730 8.19 50.024 0.98392 0.91746 0.00717 8.39 49.942 0.98387 0.91687 0.00706 8.59 49.866 0.98382 0.91632 0.00697 8.79 49.794 0.98378 0.91579 0.00690 8.99 49.729 0.98374 0.91529 0.00685 9.19 49.668 0.98370 0.91483 0.00681 9.39 49.612 0.98366 0.91440 0.00678 9.59 49.561 0.98363 0.91400 0.00676 9.79 49.515 0.98360 0.91363 0.00674 9.99 49.473 0.98357 0.91329 0.00673 10.19 49.435 0.98355 0.91298 0.00673 10.39 49.402 0.98353 0.91270 0.00673 10.59 49.371 0.98351 0.91244 0.00673 10.79 49.345 0.98349 0.91222 0.00673 10.99 49.321 0.98347 0.91201 0.00674 11.19 49.299 0.98346 0.91183 0.00674 11.39 49.281 0.98344 0.91167 0.00675 11.59 49.264 0.98343 0.91152 0.00675 11.79 49.250 0.98342 0.91139 0.00676 11.99 49.238 0.98341 0.91128 0.00676 12.19 49.227 0.98341 0.91118 0.00677 12.39 49.217 0.98340 0.91110 0.00677 12.59 49.209 0.98339 0.91102 0.00678 12.79 49.202 0.98339 0.91096 0.00678 12.99 49.196 0.98339 0.91090 0.00679 13.19 49.191 0.98338 0.91085 0.00679 13.39 49.187 0.98338 0.91081 0.00680 13.59 49.183 0.98338 0.91077 0.00680 13.79 49.180 0.98337 0.91074 0.00680 13.99 49.177 0.98337 0.91072 0.00681 14.19 49.175 0.98337 0.91070 0.00681 14.39 49.173 0.98337 0.91068 0.00681 14.59 49.172 0.98337 0.91066 0.00681 14.79 49.170 0.98337 0.91065 0.00681 14.99 49.169 0.98337 0.91064 0.00682
% Plot the gates, probabilities, currents, Vm, etc
plot(plot_time, plot_Vm); grid on ;

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by