The end operator must be used within an array index expression.
4 次查看(过去 30 天)
显示 更早的评论
Can anybody please help me to plot minf which is defined at the end. Below is my code
clear all; close all; clc;
Vrest = 0; % mV− change this to −65 ifdesired
dt = 0.01; % ms
totalTime = 200; % ms
C = 20; % uF/cm^2
V_Ca = 120; %mV %Reversal potential for Ca2+ current
V_K = -84; %mV %Reversal potential for K+ current
V_Leak = -60; %mV %Reversal potential for leak current
g_Ca = 4.4; % mS/cm^2 % Maximal conductance associated with Ca2+ current
g_K = 8; % mS/cm^2 % Maximal conductance associated with K+ current
g_Leak = 2; % mS/cm^2 % Conductance associated with leak current
% Vector oftimesteps
t = [0:dt:totalTime];
% samples = length(t);
V = zeros(size(t));
% Current input −− change this to see how different inputs affect the neuron
I_current = ones(1,length(t))*0.0;
I_current(10/dt:end) = 60; % Input of 0 microA/cm2 beginning at 50 ms and steady until end of time period.
% initializing values
V(1) = Vrest; % membrane potential is starting at its resting state
% separate functions to get the alpha and beta values
[alphaW, betaW] = w_equations(V(1));
% initializing gating variables to the asymptotic values when membrane potential
% is set to the membrane resting value based on equation 13
w(1) = (alphaW / (alphaW + betaW));
% repeat for time determined in totalTime , by each dt
for i = 1:length(t)
% calculate new alpha and beta based on last known membrane potenatial
[alphaW, betaW] = w_equations(V(i));
% conductance variables − computed separately to show how this
% changes with membrane potential in one ofthe graphs
conductance_Ca(i) = g_Ca*(m_inf(i));
conductance_K(i)=g_K*(w(i));
% retrieving ionic currents
I_Ca(i) = conductance_Ca(i)*(V(i)-V_Ca);
I_K(i) = conductance_K(i)*(V(i)-V_K);
I_Leak(i) = g_Leak*(V(i)-V_Leak);
% Calculating the input
Input = I_current(i) - (I_Ca(i) + I_K(i) + I_Leak(i));
% Calculating the new membrane potential
V(i+1) = V(i) + Input* dt*(1/C);
% getting new values for the gating variables
w(i+1) = w(i) + (alphaW *(1-w(i)) - betaW * w(i))*dt;
end
figure('Name', 'Gating Parameters')
plot(t(45/dt:end),minf(45/dt:end-1), 'r',t(45/dt:end), w(45/dt:end-1), 'g', 'LineWidth', 2)
legend('minf', 'w')
xlabel('Time (ms)')
ylabel('')
title('Gating Parameters')
figure('Name', 'Membrane Potential vs input')
subplot(2,1,1)
plot(t(10/dt:end),V(10/dt:end-1), 'LineWidth', 2)
xlabel('Time (ms)')
ylabel('Voltage (mV)')
title('Action Potential')
subplot(2,1,2)
plot(t(10/dt:end),I_current(10/dt:end), 'r', 'LineWidth', 2)
xlabel('Time (ms)')
ylabel('Voltage (mV)')
title('Input')
figure('Name', 'Conductance')
plot(t(10/dt:end),V(10/dt:end-1), 'r', t(10/dt:end), conductance_Ca(10/dt:end), 'b', t(10/dt:end), conductance_K(10/dt:end), 'g', 'LineWidth', 2)
legend('Action Potential', 'Ca+ Conductance', 'K+ Conductance')
xlabel('Time (ms)')
ylabel('Voltage (mV)')
title('Conduction of K+ and Ca+')
figure('Name', 'Currents')
plot(t(10/dt:end),I_Ca(10/dt:end), 'r',t(10/dt:end),I_K(10/dt:end), 'b', 'LineWidth', 2)
xlabel('Time (ms)')
ylabel('Current')
title('Currents')
% Special graph to show ionic current movement
Vrest = -12;
voltage = [-100:0.01:100];
for i = 1:length(voltage)
[alphaW, betaW] = w_equations(voltage(i));
tauw(i) = 1/(alphaW+betaW);
xw(i) = alphaW/(alphaW+betaW);
aW(i) = alphaW;
bW(i) = betaW;
end
figure('Name', 'Equilibrium Function');
plot(voltage, xw,'LineWidth', 2);
legend('w');
title('Equilibrium Function');
xlabel('mV')
ylabel('x(u)');
xlabel('Time (ms)')
%%%%%%%% functions section - always after main code %%%%%%%%%%%%%%%
%calculate alpha w and beta w
function [alpha_w, beta_w] = w_equations(V)
V_1 = -1.2; % mV
V_2 = 18; % mV
V_3 = 2; % mV
V_4 = 30; % mV
phi = 0.04; %1/ms %Rate scaling parameter
alpha_w = 1/2*phi* cosh((V-V_3)/(2*V_4))*(1 + tanh((V-V_3)/V_4));
beta_w = 1/2*phi* cosh((V-V_3)/(2*V_4))*(1 - tanh((V-V_3)/V_4));
end
%%%%%%%% functions section - always after main code %%%%%%%%%%%%%%%
function [minf] = m_inf(V)
V_1 = -1.2; % mV
V_2 = 18; % mV
V_3 = 2; % mV
V_4 = 30; % mV
minf = 1/2*(1 + tanh((V-V_1)/V_2));
end
0 个评论
采纳的回答
Geoff Hayes
2022-6-17
@Haya Ali - from this line
plot(t(45/dt:end),minf(45/dt:end-1), 'r',t(45/dt:end), w(45/dt:end-1), 'g', 'LineWidth', 2)
what is minf? I do not see that it is has been defined prior to this line of code. From context, the assumption is that it is an array...
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!