Help: Subplot function

1 次查看(过去 30 天)
TAC
TAC 2019-5-1
评论: TAC 2019-5-5
I am trying to customize the plots in the script " hhrun - Hodgkin Huxley model simulation for user defined input current" by Rohit Chandra. The original plot function is shown below:
for i=1:loop-1
V(i+1) = V(i) + dt*(gNa*m(i)^3*h(i)*(eNa-(V(i)+65)) + gK*n(i)^4*(eK-(V(i)+65)) + gL*(eL-(V(i)+65)) + I);
m(i+1) = m(i) + dt*(alphaM(V(i))*(1-m(i)) - betaM(V(i))*m(i));
h(i+1) = h(i) + dt*(alphaH(V(i))*(1-h(i)) - betaH(V(i))*h(i));
n(i+1) = n(i) + dt*(alphaN(V(i))*(1-n(i)) - betaN(V(i))*n(i));
end
if Plot == 1
figure
plot(t,V);
xlabel('Time');
ylabel('Membrane Potential');
title('Voltage time series');
figure
plot(V,m);
xlabel('Voltage');
ylabel('m');
title('V vs. m');
figure
plot(V,n);
xlabel('Voltage');
ylabel('n');
title('V vs. n');
figure
plot(V,h);
xlabel('Voltage');
ylabel('h');
title('V vs. h');
end
However, I am trying to incorporate those plots into one figure, where plot(t,v) would be placed across the columns in the first row and the other 3 plots would be positioned in the second row and one in each column. The code below is my attempt at trying to create subplots. When I would try to run the program, nothing happens (no results and no error messages). Then, I would hit pause and the program would continuously pause forcing me to stop the execution. However, nothing happens when I would stop the execution. Please let me know if I'm missing something is wrong. Thank you!
for i=1:loop-1
V(i+1) = V(i) + dt*(gNa*m(i)^3*h(i)*(eNa-(V(i)+65)) + gK*n(i)^4*(eK-(V(i)+65)) + gL*(eL-(V(i)+65)) + I);
m(i+1) = m(i) + dt*(alphaM(V(i))*(1-m(i)) - betaM(V(i))*m(i));
h(i+1) = h(i) + dt*(alphaH(V(i))*(1-h(i)) - betaH(V(i))*h(i));
n(i+1) = n(i) + dt*(alphaN(V(i))*(1-n(i)) - betaN(V(i))*n(i));
end
if Plot == 1
figure
subplot(2,3,1:3);
plot(t,V);
xlabel('Time');
ylabel('Membrane Potential');
title('Voltage time series');
subplot(2,3,4);
plot(V,m);
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,5);
plot(V,n);
xlabel('Voltage');
ylabel('n');
title('V vs. n');
subplot(2,3,6);
plot(V,h);
xlabel('Voltage');
ylabel('h');
title('V vs. h');
end
  1 个评论
Walter Roberson
Walter Roberson 2019-5-1
We as outsiders have no reason to expect that Plot == 1 is true.
I notice you do not have any drawnow() . However you do have figure(), which would open a new figure each time, which is defined to trigger drawing of what has been queued before that point.

请先登录,再进行评论。

回答(1 个)

imrankhan ajees
imrankhan ajees 2019-5-1
you have to use the subplot function first to plot many graphs in an figure. here i am giving you an example of the subplot you want kindly make use of it..run the below code you will get the desired output.....
x=[0.2 0.5 0.8 0.99]
y=[0.1 0.3 0.5 0.7]
subplot(2,3,1)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,2)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,3)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,4)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,5)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,6)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
  1 个评论
TAC
TAC 2019-5-5
Thank you for your help! I tried what you suggested but it still didn't work (see code below). Do you have anymore suggestions? I also attached the entire code so that you can get a better understanding.
x=[t V V V]
y=[V m n h]
subplot(2,3,1:3)
plot(x,y)
xlabel('t');
ylabel('Voltage');
title('Voltage Time Series');
subplot(2,3,4)
plot(x,y)
xlabel('Voltage');
ylabel('m');
title('V vs. m');
subplot(2,3,5)
plot(x,y)
xlabel('Voltage');
ylabel('n');
title('V vs. n');
subplot(2,3,6)
plot(x,y)
xlabel('Voltage');
ylabel('h');
title('V vs. h');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Neural Simulation 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by