Trace Marker Along Line
2 views (last 30 days)
Show older comments
Hi
I have tried writing the code to trace marker along a line ( form matlab help)to make an animation
1. it doesn't work
2. I need to do it with polar function and not plot function
Can you help?
The code:
x = linspace(0,10,1000);
y = sin(x);
plot(x,y)
hold on
p = plot(x(1),y(1),'o','MarkerFaceColor','red');
hold off
axis manual
for k = 2:length(x)
p.XData = x(k);
p.YData = y(k);
drawnow
end
3 Comments
Walter Roberson
on 23 Jan 2017
The syntax you are looking at is R2014b or later only. You will need to switch back to the set() syntax
Answers (1)
KSSV
on 23 Jan 2017
Edited: KSSV
on 23 Jan 2017
clc; clear all ;
theta = 0:0.01:2*pi;
rho = sin(2*theta).*cos(2*theta);
% convert to Cartesian for marker tracing
xx = rho.*cos(theta) ;
yy = rho.*sin(theta) ;
figure
polar(theta,rho,'r')
hold on
h = plot(xx(1),yy(1),'*b') ;
for i = 1:length(theta)
set(h,'XData',xx(i),'YData',yy(i))
pause(0.01)
end
0 Comments
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!