Trace Marker Along Line
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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
Réponses (1)
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
0 commentaires
Voir également
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!