clear one plot in multiple (hold) figure

4 visualizzazioni (ultimi 30 giorni)
Hello,
I want to follow a point by plotting him every time. I want just plot the point not all previous points.
I've tried to use this code, but it gives all points.
x = 1:0.01:25;
y = sin(x);
n = numel(x);
%figure;
for i = 1:n
h=plot(x(1:i),y(1:i),'+r');
xlim([0 25]);
ylim([-1.1 1.1]);
%refreshdata(figure,'base')
pause(0.001);
% drawnow;
delete(h)
end
How can I fix the problem ?

Risposta accettata

KALYAN ACHARJYA
KALYAN ACHARJYA il 14 Dic 2020
Modificato: KALYAN ACHARJYA il 14 Dic 2020
x = 1:0.01:25;
y = sin(x);
n = numel(x);
%figure;
for i = 1:n
h=plot(x(i),y(i),'+r');
xlim([0 25]);
ylim([-1.1 1.1]);
pause(0.001);
delete(h)
end

Più risposte (1)

Ameer Hamza
Ameer Hamza il 14 Dic 2020
Another computationally efficient approach is to create a single line object and update its XData and YData properties
x = 1:0.01:25;
y = sin(x);
n = numel(x);
%figure;
h = plot(nan, '+r');
xlim([0 25]);
ylim([-1.1 1.1]);
hold on
for i = 1:n
h.XData = x(i);
h.YData = y(i);
%refreshdata(figure,'base')
pause(0.001);
end

Categorie

Scopri di più su Graphics Performance 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