# animatedline connects the first and last point in a plot

12 views (last 30 days)
Hello guys, I've faced a problem regarding the use of animatedline as described below: I want to plot a stream of data, in real-time, using the animatedline object with 'MaximumNumPoints' set equal a specific number, let's say 50. The first 50 points are ok. For the 51st point, I set the x value to the beginning of the plot; But then as the 51st point is added to the plot, the beginning and the end of the plot will be connected to each other. So how can I remove this line?
clear
sample_rate = 50;
x = 0:sample_rate-1;
figure
h=animatedline('MaximumNumPoints',sample_rate);
axis([0 sample_rate 0 1])
i = 0;
k = 0;
while true
i = 1 + i;
drawnow
i = mod(i, sample_rate);
k = k+1;
if k == 10*sample_rate
break
end
end

Camile van der Heijden on 22 Feb 2018
Edited: Camile van der Heijden on 27 Feb 2018
I know this is a very old question, but perhaps it will still help someone. The above answer should work (although the line sample_rate = sample_rate+i ; doens't seem to do anything since it's within an if-statement for when i==0.) Anyway, it keeps the previous data on screen. If you use NaN for every 51st value, there will be a gap between the 50th and 52nd points. That way, the amount of animatedline objects in the figure won't keep going up, as instead you'll keep using the same one. This, however, also means that old points will be automatically overwritten, which might or might not be desirable. This would look like:
:
clear
sample_rate = 50;
x = 0:sample_rate-1;
figure
h=animatedline('MaximumNumPoints',sample_rate);
axis([0 sample_rate 0 1])
i = 0;
k = 0;
while true
i = 1 + i;
if mod(i,sample_rate) == 0
end
drawnow
i = mod(i, sample_rate);
k = k+1;
if k == 10*sample_rate
break
end
end

KSSV on 20 Dec 2016
Are you looking for some thing like this?
sample_rate = 50;
x = 0:sample_rate-1;
figure
h=animatedline('MaximumNumPoints',sample_rate);
axis([0 sample_rate 0 1])
i = 0;
k = 0;
while true
i = 1 + i;
pause(0.1)
drawnow
i = mod(i, sample_rate) ;
if i==0
sample_rate = sample_rate+i ;
h=animatedline('MaximumNumPoints',sample_rate);
end
k = k+1;
if k == 10*sample_rate
break
end
end