How to plot three different graphs in same window using subplots , animated line and adpoints . I have submitted my code in text box please help to run this three graphs

5 views (last 30 days)
APU CHAKRABORTY
APU CHAKRABORTY on 7 Jun 2022
Commented: VBBV on 7 Jun 2022
clc; close all;
t = -3:0.01:3;
x=@(t) exp(-t).*(t>0)+ 0.5*(t==0);
xa=x(t);
xe=( x(t)+x(-t))/2;
x0=(x(t)-x(-t))/2;
subplot(1,1,1)
curve1 = animatedline('LineWidth', 2);
axis([-3 3 -1 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('orginal signal')
hold on
plot(t,xa);
subplot(1,2,1)
curve2 = animatedline('LineWidth', 2);
axis([-3 3 0 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('Continous even signal')
hold on
plot(t,xe);
subplot(1,2,2)
curve3 = animatedline('LineWidth', 2);
axis([-3 3 -1 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('continous odd signal')
hold on
plot(t,x0);
for i = 1: length(t)
addpoints(curve1, t(i), xa(i));
addpoints(curve2, t(i), xe(i));
addpoints(curve3, t(i), x0(i));
drawnow
end

Answers (1)

VBBV
VBBV on 7 Jun 2022
clc; close all;
t = -3:0.01:3;
x=@(t) exp(-t).*(t>0)+ 0.5*(t==0);
xa=x(t);
xe=( x(t)+x(-t))/2;
x0=(x(t)-x(-t))/2;
subplot(3,1,1) % change this
curve1 = animatedline('LineWidth', 2);
axis([-3 3 -1 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('orginal signal')
hold on
plot(t,xa);
subplot(3,1,2) % change this
curve2 = animatedline('LineWidth', 2);
axis([-3 3 0 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('Continous even signal')
hold on
plot(t,xe);
subplot(3,1,3) % change this
curve3 = animatedline('LineWidth', 2);
axis([-3 3 -1 1])
grid on
xlabel('t')
ylabel('Amplitude')
title('continous odd signal')
hold on
plot(t,x0);
for i = 1: length(t)
addpoints(curve1, t(i), xa(i));
addpoints(curve2, t(i), xe(i));
addpoints(curve3, t(i), x0(i));
drawnow
end
Change the subplot layout to include all in one window.

Products

Community Treasure Hunt

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

Start Hunting!