Merge growth and decay plots

조회 수: 3 (최근 30일)
Brian Hoblin
Brian Hoblin 2016년 11월 30일
댓글: Star Strider 2016년 12월 1일
I'm trying to figure out how to merge 2 plot into one continuous plot. I have plotted the exponential growth for a capacitor charging and I have plotted the exponential decay of the capacitor discharging. I can't figure out how to combine both into one continuous plot. Here are my individual codes. First is the growth followed by the decay.
Growth
t1=0:0.0001:5*tau;
v=5;
r=10e3;
c=10e-7;
tau = r.*c;
v1=((0-v).*exp(-t1/tau))+v;
hold on
plot(t1,v1)
hold on
grid on
title('Capacitor Charging')
xlabel('Time (s)')
ylabel('Voltage across capacitor (V)')
Decay
t2=0:0.0001:5*tau;
v=5;
r=10e3;
c=10e-7;
tau = r.*c;
v2=v.*exp((-t2/tau));
hold on
plot(t2,v2)
hold on
grid on
title('Capacitor Discharge')
xlabel('Time (s)')
ylabel('Voltage across capacitor (V)')
I've tried using heaviside but I haven't had any success. Maybe I'm using heaviside wrong. The following will run but only the growth portion shows up on the graph. Can anyone point out what I'm doing wrong please? I'd really appreciate the help.
t1=0:0.0001:5*tau;
t2=((5*tau)+0.0001):0.0001:5*tau;
v=5;
r=10e3;
c=10e-7;
tau = r.*c;
v1=((0-v).*exp(-t1/tau))+v;
hold on
v2=v.*exp((-1/tau).*heaviside(t2-10*tau));
hold on
t=[t1,t2];
vf=[v1,v2];
plot(t,vf)

채택된 답변

Star Strider
Star Strider 2016년 12월 1일
Try this:
figure
plot(t1, v1)
hold on
plot(t1(end)+t2, v2)
hold off
grid
legend('Charge', 'Discharge')
xlabel('Time (s)')
ylabel('Voltage across capacitor (V)')
  댓글 수: 2
Brian Hoblin
Brian Hoblin 2016년 12월 1일
Thank you very much!
Star Strider
Star Strider 2016년 12월 1일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Switches and Breakers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by