clear one plot in multiple (hold) figure

3 Ansichten (letzte 30 Tage)
islam dib
islam dib am 14 Dez. 2020
Beantwortet: Ameer Hamza am 14 Dez. 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 ?

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 14 Dez. 2020
Bearbeitet: KALYAN ACHARJYA am 14 Dez. 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

Weitere Antworten (1)

Ameer Hamza
Ameer Hamza am 14 Dez. 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

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by