How to plot data point by point and erasing the last one?

13 views (last 30 days)
Miroslav Mitev
Miroslav Mitev on 26 Apr 2016
Commented: Miroslav Mitev on 27 Apr 2016
Hello, I need to plot my data point by point, but I also need just one point on the plot (when new point arrived the one before to disappear). That is my code everything works good I just want to fix that:
y=[1,3,2,3,3];
n=numel(y)
figure
xlim([0 2])
ylim([0 2])
grid on
hold on
for ii=1:n
if y(ii)<1.1
scatter(0.5,0.5),hold on
pause(1)
else if y(ii)<2.2
scatter(1.5,1.5),hold on
else
scatter(0.5,1.5)
pause(1)
end
end
end

Accepted Answer

MHN
MHN on 26 Apr 2016
Edited: MHN on 26 Apr 2016
I have done pretty much animated plot with Matlab, What you need is a little trick !!
y=[1,3,2,3,3];
n=numel(y)
figure
xlim([0 2])
ylim([0 2])
grid on
hold on
for ii=1:n
if y(ii)<1.1
scatter(0.5,0.5) ,hold on
pause(1)
scatter(0.5,0.5,'w') ,hold on
else if y(ii)<2.2
scatter(1.5,1.5) ,hold on
pause(1)
scatter(1.5,1.5, 'w') ,hold on
else
scatter(0.5,1.5)
pause(1)
scatter(0.5,1.5,'w')
end
end
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by