How to adjust plot?

2 ビュー (過去 30 日間)
Haya Ali
Haya Ali 2022 年 6 月 27 日
コメント済み: Haya Ali 2022 年 6 月 27 日
How can I adjust my x axis to start from 0 in the figures. When I set xlim then the figures become totally changed. Please help me to adjust the code.
clear all; close all; clc;
Vrest = 0; % mV− change this to −65 ifdesired
dt = 0.01; % ms
totalTime = 150; % 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
V_1 = -1.2; % mV
V_2 = 18; % mV
% 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(45/dt:end) = 90; % 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));
minf = 1/2*(1 + tanh((V-V_1)/V_2));
% conductance variables − computed separately to show how this
% changes with membrane potential in one ofthe graphs
conductance_Ca(i) = g_Ca*(minf(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', 'Membrane Potential vs input')
%subplot(2,1,1)
%plot(t(45/dt:end),V(45/dt:end-1), 'LineWidth', 2)
%xlabel('Time (ms)')
%ylabel('Voltage (mV)')
%title('Action Potential')
%subplot(2,1,2)
%plot(t(45/dt:end),I_current(45/dt:end), 'r', 'LineWidth', 2)
%xlabel('Time (ms)')
%ylabel('Voltage (mV)')
%title('Input')
figure('Name', 'Membrane Potential vs input')
plot(t(45/dt:end),V(45/dt:end-1), 'LineWidth', 2)
xlabel('Time (ms)')
ylabel('Voltage (mV)')
title('Action Potential')
figure('Name', 'Gating Parameters')
plot(t(45/dt:end),w(45/dt:end-1), 'g','LineWidth', 2)
hold on
plot(t(45/dt:end),minf(45/dt:end), 'm','LineWidth', 2)
legend('w','minf')
xlabel('Time (ms)')
ylabel('')
title('Gating Parameters')
figure('Name', 'Conductance')
plot(t(45/dt:end),V(45/dt:end-1), 'r', t(45/dt:end), conductance_Ca(45/dt:end), 'b', t(45/dt:end), conductance_K(45/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(45/dt:end),I_Ca(45/dt:end), 'r',t(45/dt:end),I_K(45/dt:end), 'b', 'LineWidth', 2)
legend('ICa+', 'IK+')
xlabel('Time (ms)')
ylabel('Current')
title ('Currents')
% Special graph to show ionic current movement
Vrest = 0;
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_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
  2 件のコメント
KSSV
KSSV 2022 年 6 月 27 日
You x-data is from 40 to 140.....how you can limit from 0?
Haya Ali
Haya Ali 2022 年 6 月 27 日
Can I adjust data from 0 to 140?

サインインしてコメントする。

採用された回答

KSSV
KSSV 2022 年 6 月 27 日
編集済み: KSSV 2022 年 6 月 27 日
Don't use:
plot(t(45/dt:end),V(45/dt:end-1), 'LineWidth', 2)
instead use:
plot(t,V, 'LineWidth', 2)
Like this:
clear all; close all; clc;
Vrest = 0; % mV− change this to −65 ifdesired
dt = 0.01; % ms
totalTime = 150; % 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
V_1 = -1.2; % mV
V_2 = 18; % mV
% Vector oftimesteps
t = [0:dt:totalTime];
% samples = length(t);
% Current input −− change this to see how different inputs affect the neuron
I_current = ones(1,length(t))*0.0;
I_current(45/dt:end) = 90; % Input of 0 microA/cm2 beginning at 50 ms and steady until end of time period.
V = zeros(size(t)) ;
w = zeros(size(t)) ;
conductance_Ca = zeros(size(t)) ;
conductance_K = zeros(size(t));
I_Ca = zeros(size(t)) ;
I_K = zeros(size(t)) ;
I_Leak = zeros(size(t)) ;
% 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)-1
% calculate new alpha and beta based on last known membrane potenatial
[alphaW, betaW] = w_equations(V(i));
minf = 1/2*(1 + tanh((V-V_1)/V_2));
% conductance variables − computed separately to show how this
% changes with membrane potential in one ofthe graphs
conductance_Ca(i) = g_Ca*(minf(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', 'Membrane Potential vs input')
%subplot(2,1,1)
%plot(t,V, 'LineWidth', 2)
%xlabel('Time (ms)')
%ylabel('Voltage (mV)')
%title('Action Potential')
%subplot(2,1,2)
%plot(t,I_current, 'r', 'LineWidth', 2)
%xlabel('Time (ms)')
%ylabel('Voltage (mV)')
%title('Input')
figure('Name', 'Membrane Potential vs input')
plot(t,V, 'LineWidth', 2)
xlabel('Time (ms)')
ylabel('Voltage (mV)')
title('Action Potential')
figure('Name', 'Gating Parameters')
plot(t,w, 'g','LineWidth', 2)
hold on
plot(t,minf, 'm','LineWidth', 2)
legend('w','minf')
xlabel('Time (ms)')
ylabel('')
title('Gating Parameters')
figure('Name', 'Conductance')
plot(t,V, 'r', t, conductance_Ca, 'b', t, conductance_K, '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,I_Ca, 'r',t,I_K, 'b', 'LineWidth', 2)
legend('ICa+', 'IK+')
xlabel('Time (ms)')
ylabel('Current')
title ('Currents')
% Special graph to show ionic current movement
Vrest = 0;
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_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
  1 件のコメント
Haya Ali
Haya Ali 2022 年 6 月 27 日
Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by