필터 지우기
필터 지우기

A moving point plot in MATLAB figure with animation between 2 point

조회 수: 3 (최근 30일)
Farhad
Farhad 2014년 12월 28일
댓글: passioncoding 2019년 1월 3일
Hi everybody; i want to make a moving point animation between a = [41.50,-70.95] b = [ 41.80 , -70.5].How can i do this?

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 12월 29일
Farhad - what kind of animation do you want? Should the point follow a straight line, or do something else? If the former, then try the following
a = [41.50, -70.95];
b = [ 41.80 , -70.50];
% straight line function from a to b
func = @(x)a(2) + (a(2)-b(2))/(a(1)-b(1))*(x-a(1));
% determine the x values
x = linspace(a(1),b(1),50);
% determine the y values
y = func(x);
% create the figure
figure;
% get a handle to a plot graphics object
hPlot = plot(NaN,NaN,'ro');
% set the axes limits
xlim([min(a(1),b(1)) max(a(1),b(1))]);
ylim([min(a(2),b(2)) max(a(2),b(2))]);
% iterate through each point on line
for k=1:length(x)
% update the plot graphics object with the next position
set(hPlot,'XData',x(k),'YData',y(k));
% pause for 0.5 seconds
pause(0.5);
end
So on each iteration of the for loop, we just replace the (x,y) coordinate of the last drawn point with the new one and then wait for half a second before drawing the next point, which creates a kind of animation.
  댓글 수: 7
Farhad
Farhad 2014년 12월 30일
Thank you Geof,i will say my regards to you in presentation.
passioncoding
passioncoding 2019년 1월 3일
Can I ask same question related to this kind a animation? plz help me

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by