Plotting multiple line on Matlab but only last plot showed

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 16일
편집: Azzi Abdelmalek 2012년 9월 16일
plot(0:h:t,V_trace1,'r')
hold on
plot(0:h:t,V_trace2,'r')
figure
Wayne King
Wayne King 2012년 9월 16일
편집: Wayne King 2012년 9월 16일
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

카테고리

도움말 센터File Exchange에서 Material Sciences에 대해 자세히 알아보기

태그

질문:

2012년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by