How can i correct the error generated from running this code

2 Ansichten (letzte 30 Tage)
Kwabena Danso
Kwabena Danso am 7 Aug. 2018
Kommentiert: Peter Meglis am 7 Aug. 2018
a = 20E-6; % Cell radius (m) d = 2*a; % Cell diameter (m) L = 40.0E-6; % Cell length (m) temp = 6.3; % Temperature (deg. C) gmax_Na = (120E-3)*100^2; % Maximum sodium conductance per unit area (S/m^2) gmax_K = (36E-3)*100^2; % Maximum potassium conductance per unit area (S/m^2) co_Na = 491E-3; % Extracellular Na concentration (M/L) ci_Na = 50E-3; % Intracellular Na concentration (M/L) co_K = 20.11E-3; % Extracellular K concentration (M/L) ci_K = 400E-3; % Intracellular K concentration (M/L) C_m = (1.0E-6)*100^2; % Membrane capacitance per unit area (F/m^2) b = 0.02; % Relative sodium to potassium conductance delta_t = 1.0E-6; % Time step (s) max_time = 20.0E-3; % Maximum time (s) pulse_width = 10E-6; % Stimulus pulse width (s) pulse_amp = 59E-9; % Stimulus pulse amplitude (A)
% Compute cell parameter values Area = 2*(pi*a^2) + 2*pi*a*L; %area in m^2 C = Area*C_m; maxcond_Na = Area*gmax_Na; maxcond_K = Area*gmax_K; Na_Battery = V_Na(co_Na, ci_Na, temp); K_Battery = V_K(co_K, ci_K, temp); V_rest = V_r(co_Na, ci_Na, co_K, ci_K, temp, b); m_o = m_bound(V_rest); n_o = n_bound(V_rest); h_o = h_bound(V_rest);
% Set up the time vector t = zeros(floor(max_time/delta_t),1);
for i = 1:floor(max_time/delta_t) t(i) = (i-1)*delta_t; end
% Specify the initial conditions vector y0 = [V_rest, m_o, h_o, n_o]; options = odeset();
% Invoke the solver [T,Y] = ode45(@odefun, t, y0, options, C, maxcond_Na, maxcond_K, Na_Battery, K_Battery,pulse_width, pulse_amp);
% Plot the solution figure(1) plot(T,(Y(:,1)*10^3)) grid xlabel('Time(s)') ylabel('Transmembrane Potential(mV)') title('Action Potential')
figure(2) plot(T,Y(:,2)) hold on plot(T,Y(:,3),'r') hold on plot(T,Y(:,4),'g') grid xlabel('Time(s)') ylabel('Gating Variable') title('Gating Varible dynamics')
function ah = alpha_h(Vm) Vm = Vm/1.0E-3; ah = 0.07*exp(-0.05*(Vm+60));
function am = alpha_m(Vm) Vm = Vm/1.0E-3; if Vm ~= -35 am = -0.1*(Vm+35)/(exp(-0.1*(Vm+35))-1); end if Vm == -35 up = Vm + 1.0E-4; down = Vm - 1.0E-4; am =(-0.1*(up+35)/(exp(-0.1*(up+35))-1)+(-0.1)*(down+35)/(exp(-0.1*(down+35))-1))/2; end function an = alpha_n(Vm) Vm = Vm/1.0E-3; if Vm ~= -50 an = -0.01*(Vm+50)/(exp(-0.1*(Vm+50))-1); end if Vm == -50 up = Vm + 1.0E-4; down = Vm - 1.0E-4; an = (-0.01*(up+50)/(exp(-0.1*(up+50))-1) + -0.01*(down+50)/(exp(-0.1*(down+50))-1))/2; end function bh = beta_h(Vm) Vm = Vm/1.0E-3; bh = 1/(1+exp(-0.1*(Vm+30))); function bm = beta_m(Vm) Vm = Vm/1.0E-3; bm = 4.0*exp(-(Vm+60)/18); function bn = beta_n(Vm) Vm = Vm/1.0E-3; bn = 0.125*exp(-0.0125*(Vm+60)); function I = Current(t,pw,amp) if t >= 0.0 & t <= pw I = amp; else I = 0.0; end function hb = h_bound(Vm) hb = alpha_h(Vm)/(alpha_h(Vm)+beta_h(Vm)); function mb = m_bound(Vm) mb = alpha_m(Vm)/(alpha_m(Vm)+beta_m(Vm)); function nb = n_bound(Vm) nb = alpha_n(Vm)/(alpha_n(Vm)+beta_n(Vm));
function dy = odefun(t, y, Cm, GNamax, GKmax, VNa, VK, pw, amp); mf = m_bound(y(1)); hf = h_bound(y(1)); nf = n_bound(y(1)); taum = tau_m(y(1)); tauh = tau_h(y(1)); taun = tau_n(y(1)); dy = [-(GKmax/Cm)*(y(4)^4)*(y(1)-VK)-(GNamax/Cm)*(y(2)^3)*y(3)*(y(1)VNa)+Current(t,pw,amp)/Cm;
(mf-y(2))/taum; (hf-y(3))/tauh; (nf-y(4))/taun]; function th = tau_h(Vm) th = 1/((alpha_h(Vm)+beta_h(Vm)))*(1/1000); function tm = tau_m(Vm) tm = (1/(alpha_m(Vm)+beta_m(Vm)))*(1/1000); function tn = tau_n(Vm) tn = (1/(alpha_n(Vm)+beta_n(Vm)))*(1/1000);
function VK = V_K(co_K, ci_K, temp) R = 8.314; % Reiberg gas constant (joules/(mole*kelvin F = 9.648E4; % Faraday's constant (coulombs/mole). Z = 1; % Sodium and potassium ionic valence. TKelvin = 273.15 + temp; VK = ((R*TKelvin)/(Z*F))*log((co_K)/(ci_K)); function VNa = V_Na(co_Na, ci_Na, temp) R = 8.314; % Reiberg gas constant (joules/(mole*kelvin)). F = 9.648E4; % Faraday's constant (coulombs/mole). Z = 1; % Sodium and potassium ionic valence. TKelvin = 273.15 + temp; VNa = ((R*TKelvin)/(Z*F))*log((co_Na)/(ci_Na)); function Vr = V_r(coNa,ciNa,coK,ciK,T,b) R = 8.314; % Reiberg gas constant (joules/(mole*kelvin)). F = 9.648E4; % Faraday's constant (coulombs/mole). Z = 1; % Sodium and potassium ionic valence. TKelvin = 273.15 + T; Vr = ((R*TKelvin)/(Z*F))*log((coK + b*coNa)/(ciK + b*ciNa));
  1 Kommentar
Adam Danz
Adam Danz am 7 Aug. 2018
This is too difficult to read. Please format your code by using the {} button and please explain the error you're getting (copy the error message) and what line produces the error.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Kwabena Danso
Kwabena Danso am 7 Aug. 2018
I have attached the the .m file which has the code.
After running it, i get this error:
Error: File: XXX.m Line: 45 Column: 3 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
How can i rectify this.Thanks
  1 Kommentar
Peter Meglis
Peter Meglis am 7 Aug. 2018
Kwabena,
You can continue parameters onto the next line using "..."
[T,Y] = ode45(@odefun, t, y0, options, C, maxcond_Na, maxcond_K, Na_Battery, K_Battery,pulse_width, ...
pulse_amp);
On line 120, you're missing (I assume) an *
...(y(1)*VNa)...
I can't correct the rest of the syntax errors, make sure your functions have corresponding 'end' statements. Take a look at this Matlab Answer about nesting functions and using 'end':
https://www.mathworks.com/matlabcentral/answers/81085-function-without-matching-end
Hope this helps

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by