animatedline connects the first and last point in a plot

2 visualizzazioni (ultimi 30 giorni)
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;
received_data = rand;
addpoints(h,x(i),received_data);
drawnow
i = mod(i, sample_rate);
k = k+1;
if k == 10*sample_rate
break
end
end

Risposte (2)

Camile van der Heijden
Camile van der Heijden il 22 Feb 2018
Modificato: Camile van der Heijden il 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;
received_data = rand;
addpoints(h,x(i),received_data);
if mod(i,sample_rate) == 0
addpoints(h,x(i)+1,NaN);
end
drawnow
i = mod(i, sample_rate);
k = k+1;
if k == 10*sample_rate
break
end
end

KSSV
KSSV il 20 Dic 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;
received_data = rand;
addpoints(h,x(i),received_data);
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

Categorie

Scopri di più su Animation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by