animatedline connects the first and last point in a plot

1 vue (au cours des 30 derniers jours)
Mohammad Javad Taheri
Mohammad Javad Taheri le 19 Déc 2016
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

Réponses (2)

Camile van der Heijden
Camile van der Heijden le 22 Fév 2018
Modifié(e) : Camile van der Heijden le 27 Fév 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 le 20 Déc 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

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by