Getting a weird plot
Show older comments
Not sure why I'm getting this this plot ... reaching out to MATLAB Gods Should look like "HH", looks like "HH Wrong"
%simulation time simulationTime = 100; %in miliseconds deltaT = 0.1; t=0:deltaT:simulationTime;
%specify the external current I changeTimes = [0]; currentLevels = [50];
% I(1:500) = currentLevels; I(501:2000) = 0; I(2001:numel(t)) = currentLevels;
%Constant Parameters gbar_K=36; gbar_Na=120; g_L=0.3; E_K=-12; E_Na=115; E_L=10.6; C=1;
%Set the initial states V=0; alpha_n = 0.01 * ( (10-V) / (exp((10-V)/10)) ); beta_n = 0.125*exp(-V/80); alpha_m = 0.1*((25-V) / (exp((25-V)/10)-1) ); beta_m = 4*exp(-V/18); alpha_h = 0.07*exp(-V/20); beta_h = 1/(exp((30-V)/10)+1);
n(1) = alpha_n/(alpha_n+beta_n); m(1) = alpha_m/(alpha_m+beta_m); h(1) = alpha_h/(alpha_h+beta_h);
for i=1:numel(t)-1 alpha_n(i) = 0.01*( (10-V(i)) / (exp((10-V(i))/10)-1)); beta_n(i) = 0.125*exp(-V(i)/80); alpha_m(i) = 0.1*( (25-V(i)) / (exp((25-V(i))/10)-1) ); beta_m = 4*exp(-V(i)/18); alpha_h = 0.07*exp(-V(i)/20); beta_h = 1/(exp((30-V(i))/10)+1);
%Calculate the Currents
I_Na = (m(i)^3) *gbar_Na * h(i) * (V(i)-E_Na);
I_K = (n(i)^4 * gbar_K * (V(i)-E_K));
I_L = g_L * (V(i)-E_L);
I_ion = I(i) - I_K - I_Na - I_L;
%Calclate the Derivatives
V(i+1) = V(i) + deltaT*I_ion/C;
n(i+1) = n(i) + deltaT*(alpha_n(i) * (1-n(i)) - beta_n(i) * n(i));
m(i+1) = m(i) + deltaT*(alpha_m(i) * (1-m(i)) - beta_m(i) * m(i));
h(i+1) = h(i) + deltaT*(alpha_h(i) * (1-h(i)) - beta_h(i) * h(i));
end
%Set resting potential to -70 mV
V = V-70
%Plot Voltage
plot(t,V, 'LineWidth', 3) hold on legend({'voltage'}) ylabel('Voltage (mv)') xlabel('time (ms)') title ('voltage over Time in Simulated Neuron')
%Plot Conductance
figure p1 = plot(t,gbar_K*n.^4,'LineWidth',2); hold on p2 = plot(t,gbar_Na*(m.^3).*h, 'r', 'LineWidth',2); legend([p1, p2], 'Conductance for Potassium', 'Conductance for Sodium') ylabel ('Conductance') xlabel ('time (ms)') title ('Conductance for Potassium and Sodium Ions in Simulated Neurons')
Index exceeds matrix dimensions.
Error in HH (line 49) m(i+1) = m(i) + deltaT*(alpha_m(i) * (1-m(i)) - beta_m(i) * m(i));
Thanks!
Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!