clear one plot in multiple (hold) figure

3 vues (au cours des 30 derniers jours)
islam dib
islam dib le 14 Déc 2020
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 ?

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Déc 2020
Modifié(e) : KALYAN ACHARJYA le 14 Déc 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

Plus de réponses (1)

Ameer Hamza
Ameer Hamza le 14 Déc 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

Catégories

En savoir plus sur Graphics Performance 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