Trace Marker Along Line
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 23 de En. de 2017
The syntax you are looking at is R2014b or later only. You will need to switch back to the set() syntax
Respuestas (1)
KSSV
el 23 de En. de 2017
Editada: KSSV
el 23 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Animation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!