How to produce results of script in table

1 回表示 (過去 30 日間)
Anthony Koning
Anthony Koning 2021 年 12 月 15 日
編集済み: Chris 2021 年 12 月 15 日
Hi, would anyone know how to produce the results of the script in a neat table format similar to the last line of this script? Removing the comment only produces the results of the final calculation in a 1x8 table, rather than the expected 9x8 table. Thanks
% Set parameters (constants)
tStart = -.200 ; % start time, millisec
tEnd = .200 ; % end time, millisec
deltaT = 0.050 ; % time step, millisec
nStep = ceil((tEnd-tStart)/deltaT) ; % number of time steps
outputInterval = 20 ; % number of time steps between screen output
Vrest = -60 ; % resting potential, mV
EK = -72.1 ; % potassium Nernst potential, mV
ENa = 52.4 ; % sodium Nernst potential, mV
EL = -49.2 ; % leak Nernst potential, mV
gK_max = 36 ; % potassium saturation conductance, mS/cm^2
gNa_max = 120 ; % sodium saturation conductance, mS/cm^2
gL_max = 0.3 ; % leak saturation conductance, mS/cm^2
Cm = 1 ; % Membrane Capacitance
Jstim = 200 ;
StimDur = .15 ;
time = tStart:deltaT;tEnd
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set initial value of state variables
Vm = Vrest ; % membrane potential, mV
n = 0.31768 ; % initial value of n gate
m = 0.05293 ; % initial value of m gate
h = 0.59612 ; % initial value of h gate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for iStep = 1:nStep
% Compute ion currents at tNow, then apply stimulus current
if( 0<=tNow && tNow<StimDur ) % start stimulus current at tNow=0
Is = Jstim ;
else % stop stimulus when tNow = StimDur
Is = 0 ;
end
JNa = gNa_max.*m.^3.*h.*(Vm-ENa) ;
JK = gK_max.*n.^4.*(Vm-EK) ;
JL = gL_max.*(Vm-EL);
Jion = JNa+JK+JL
dV_dt = (Is.*Jion)./Cm
% Compute gates' opening and closing rates
[a_n, b_n] = get_n_rates(Vm)
[a_m, b_m] = get_m_rates(Vm)
[a_h, b_h] = get_h_rates(Vm)
% Compute change in state variables
deltaVm = ((Is - JNa - JK - JL)./Cm) .* deltaT ;
delta_m = (a_m.*(1-m) - b_m.*(m)) .* deltaT ;
delta_n = (a_n.*(1-n) - b_n.*(n)) .* deltaT ;
delta_h = (a_h.*(1-h) - b_h.*(h)) .* deltaT ;
if mod(iStep,outputInterval) == 0
fprintf(iStep, tNow, Is, Vm, deltaVm, n, m, h) ;
end % if mod(tNow)
%Update State Veriable
Vm = Vm + deltaVm ;
m = m + delta_m
n = n + delta_n
h = h + delta_h
tNow = tStart + iStep.*deltaT
% Update state variables
plot_Vm(iStep) = Vm ;
plot_time(iStep) = tNow ;
end % for iStep
%T = table(iStep, tNow, Is, Vm, deltaVm, n, m, h)

採用された回答

Chris
Chris 2021 年 12 月 15 日
編集済み: Chris 2021 年 12 月 15 日
Your variables are all updated in place, overwriting the previous state.
You could make an array out of each variable, and update the arrays like so:
m(iStep) = m(iStep-1) + delta_m(istep);
But at this point, it's probably easiest to make new variables that store the output at the end of the loop:
mAll(iStep) = m;
nAll(iStep) = n;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by