Plotting multiple line on Matlab but only last plot showed
Mostrar comentarios más antiguos
Below is my code. I would like to have two lines show on the same plot, but the code below only plot the very last plot command. Can you advise me what I need to change to get the code to have two lines show, one for v_trace1 and second for vtrace2 on the same graph.
Ia = 1.5; Ib = 1; C = 2; R = 10; tau = R*C;
tstop = 200; % ms
V_inf = Ia*R;
h = 5;
V1 = 0; V_trace1 = [V1];
V2 =0; V_trace2 = [V2];
for t = h:h:tstop+100
% Euler method: V(t+h) = V(t) + h*dV/dt
V1 = V1 +h*(- (V1/(R*C)) + (Ia/C));
V2 = V2 +h*(- (V2/(R*C)) + (Ib/C));
% Stop current injection
if (t == tstop)
Ia = 0;
Ib = 0;
end
V_trace1 = [V_trace1 V1];
V_trace2 = [V_trace2 V2];
plot(0:h:t,V_trace1,'r')
plot(0:h:t,V_trace2,'r')
axis([0 tstop+100 -V_inf V_inf])
end
Respuestas (2)
Azzi Abdelmalek
el 16 de Sept. de 2012
Editada: Azzi Abdelmalek
el 16 de Sept. de 2012
plot(0:h:t,V_trace1,'r')
hold on
plot(0:h:t,V_trace2,'r')
figure
Wayne King
el 16 de Sept. de 2012
Editada: Wayne King
el 16 de Sept. de 2012
Hold the plot on:
Ia = 1.5; Ib = 1; C = 2; R = 10; tau = R*C;
tstop = 200; % ms
V_inf = Ia*R;
h = 5;
V1 = 0; V_trace1 = [V1];
V2 =0; V_trace2 = [V2];
for t = h:h:tstop+100
% Euler method: V(t+h) = V(t) + h*dV/dt
V1 = V1 +h*(- (V1/(R*C)) + (Ia/C));
V2 = V2 +h*(- (V2/(R*C)) + (Ib/C));
% Stop current injection
if (t == tstop)
Ia = 0;
Ib = 0;
end
V_trace1 = [V_trace1 V1];
V_trace2 = [V_trace2 V2];
plot(0:h:t,V_trace1,'b'); hold on;
plot(0:h:t,V_trace2,'r')
axis([0 tstop+100 -V_inf V_inf])
end
Categorías
Más información sobre Material Sciences en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!