Help with animating a line correctly
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Emerson Butler
el 30 de Oct. de 2018
Comentada: Emerson Butler
el 30 de Oct. de 2018
Thanks in advance for any help, I am writing a small file to animate the plotting of the locus of an elliptical planar electric field over time. I am wanting it to be animated to show how the electric field can be right or left handed polarized. When I run the code, the plot draws the outline of the locus instantaneously, and then draws lines from a point out to the circle one by one over time. It draws these lines in the correct way, i.e. clockwise or counterclockwise, but I'd rather they didn't exist, and that instead the outline of the locus is the thing that is drawn over time. Here's what I have so far:
freq = 1; % Frequency in Hz
w = 2*pi*freq; % Angular Frequency
epsr = 1; % Relative Permittivity
eps0 = 10^(-9)/(36*pi); % Permittivity of free space
mu0 = 4*pi*10^(-7); % Permeability of free space
k = w*sqrt(epsr*eps0*mu0); % Spatial Frequency
ax = 1; % Ex Magnitude
ay = 2; % Ey Magnitude
delta = 0; % Phase Shift Angle
z = 0; % Position (kept at 0)
t = 0:(1/freq)/100:1/freq; % Time starts at 0, increments 100 times per cycle, stops after 1 cycle
Ex = ax*sin(w*t+k*z);
Ey = ay*cos(w*t+k*z+delta);
axis([-2,2,-2,2])
%This for loop is what does the drawing
for idx = 1:length(t)
h = animatedline(Ex,Ey);
addpoints(h,Ex(idx),Ey(idx));
drawnow
end
0 comentarios
Respuesta aceptada
M
el 30 de Oct. de 2018
Is this what you're looking for:
%This for loop is what does the drawing
for idx = 1:length(t)
figure(1);
clf;
plot(Ex(1:idx),Ey(1:idx));
drawnow
end
Más respuestas (0)
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!