Hello,
I want to simulate a heart beating graph (like on an ECG = electrocardiogram). For that I have the data for this plot and I want to animate the line, so it is appearing point by point and after the last point is plotted, it starts again (https://www.youtube.com/watch?v=XV11kplLoxw).
I have the code for the plot appearing in the graph (so "first" time it runs through), but then I do not know how to "delete" the line point by point from the beginning, so I can plot the graph again point by point.
My first try was to paint over the plotted line with a white one (and the same data), but it does not work perfectly ...
I hope the question is understandable, else please ask the missing points.
Thanks in advance.
Regards,
elchico
.
My code without the "deleting step":
filename = 'heartbeating_data.dat';
delimiter = '\t';
M_RTC = dlmread(filename,delimiter);
time = M_RTC(:,1);
data = M_RTC(:,2);
a1 = animatedline('Color','r', 'LineWidth',2);
title('Heartbeating')
xlabel('time / s')
ylabel('|Z| (norm., 4 kHz)')
axis([0 10 0.99 1.03])
x = time;
for k = 1:length(x);
xk = x(k,1);
y = data(k,1);
addpoints(a1,xk,y);
drawnow
pause(0.0005);
end
My code with the painting over:
filename = 'heartbeating_data.dat';
delimiter = '\t';
M_RTC = dlmread(filename,delimiter);
time = M_RTC(:,1);
data = M_RTC(:,2);
a1 = animatedline('Color','r', 'LineWidth',2);
a2 = animatedline('Color','w', 'LineWidth',10);
title('Heartbeating')
xlabel('time / s')
ylabel('|Z| (norm., 4 kHz)')
axis([0 10 0.99 1.03])
x = time;
for ii = 1:10
for k = 1:length(x);
xr = x(k,1);
yr = data(k,1);
addpoints(a1,xr,yr);
if k < (length(x)-9)
xw = x(k+9,1);
yw = data(k+9,1);
elseif k < length(x)
xw = x(length(x)-k,1);
yw = data(length(x)-k,1);
else
xw = 12;
yw = 12;
end
addpoints(a2,xw,yw);
drawnow
pause(0.0005);
end
end