clear one plot in multiple (hold) figure

2 次查看(过去 30 天)
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 ?

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-12-14
编辑:KALYAN ACHARJYA 2020-12-14
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

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2020-12-14
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

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by