Trace Marker Along Line

2 views (last 30 days)
Shani Gal
Shani Gal on 22 Jan 2017
Edited: KSSV on 23 Jan 2017
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
Shani Gal
Shani Gal on 23 Jan 2017
Version 7.7.0.471 (R2008b)
Walter Roberson
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

Sign in to comment.

Answers (1)

KSSV
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

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!