Trace Marker Along Line

2 vues (au cours des 30 derniers jours)
Shani Gal
Shani Gal le 22 Jan 2017
Modifié(e) : KSSV le 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 commentaires
Shani Gal
Shani Gal le 23 Jan 2017
Version 7.7.0.471 (R2008b)
Walter Roberson
Walter Roberson le 23 Jan 2017
The syntax you are looking at is R2014b or later only. You will need to switch back to the set() syntax

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 23 Jan 2017
Modifié(e) : KSSV le 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

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by