Help: Subplot function

조회 수: 18 (최근 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에서 Windows에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by