Help: Subplot function

1 view (last 30 days)
TAC
TAC on 1 May 2019
Commented: TAC on 5 May 2019
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 Comment
Walter Roberson
Walter Roberson on 1 May 2019
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.

Sign in to comment.

Answers (1)

imrankhan ajees
imrankhan ajees on 1 May 2019
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 Comment
TAC
TAC on 5 May 2019
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');

Sign in to comment.

Categories

Find more on Neural Simulation in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!