Help with animating a line correctly

5 views (last 30 days)
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

Accepted Answer

M
M on 30 Oct 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
  1 Comment
Emerson Butler
Emerson Butler on 30 Oct 2018
Perfect! I moved my axis statement to within the for loop, right after the plot function since it was adjusting the axes as it drew and I'd prefer it to be a preset window. Thank you!

Sign in to comment.

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by