Can you use animatedline with subplot, using addpoints (MATLAB2016a)

I am trying to use addpoints (with animatedline) in order to create an animated figure in a subplot. The code works on its own, but as soon as it's added to a subplot, it only plots the axes.
% Create random signals
time = 1:100;
signal_1 = rand(100,1);
signal_2 = rand(100,1);
% For plotting correlation line..need all values first
corr_line = animatedline;
for start_point = 0:80
sig1_cut = signal_1(start_point+1:start_point+1+19);
sig2_cut = signal_2(start_point+1:start_point+1+19);
corr_pre = corrcoef(sig1_cut,sig2_cut);
corr_fin(start_point+1) = corr_pre(2,1);
end
x_plot = 0:80;
n = 1;
subplot(3,1,1)
axis([-0.1 80 -1 1])
for start_point = 0:80
addpoints(corr_line,x_plot(n),corr_fin(n))
drawnow
n = n+1;
pause(0.01)
end
Thanks!

 채택된 답변

James Smith
James Smith 2017년 5월 15일
Yes you can! The function animatedline uses your current axis to work in. In this case there isn't one so it opens a new figure to plot it in, Then when you later call subplot it erases that axis.
To have it work in a subplot, move your your subplot command to before the animatedline bit of code, so the animated line will now be plotted in the subplot instead.
% Create random signals
time = 1:100;
signal_1 = rand(100,1);
signal_2 = rand(100,1);
% For plotting correlation line..need all values first
subplot(3,1,1)
corr_line = animatedline;
for start_point = 0:80
sig1_cut = signal_1(start_point+1:start_point+1+19);
sig2_cut = signal_2(start_point+1:start_point+1+19);
corr_pre = corrcoef(sig1_cut,sig2_cut);
corr_fin(start_point+1) = corr_pre(2,1);
end
x_plot = 0:80;
n = 1;
axis([-0.1 80 -1 1])
for start_point = 0:80
addpoints(corr_line,x_plot(n),corr_fin(n))
drawnow
n = n+1;
pause(0.01)
end

추가 답변 (0개)

카테고리

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

질문:

2017년 5월 15일

댓글:

2017년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by