Help with animating a line correctly

조회 수: 5 (최근 30일)
Emerson Butler
Emerson Butler 2018년 10월 30일
댓글: Emerson Butler 2018년 10월 30일
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

채택된 답변

M
M 2018년 10월 30일
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
Emerson Butler
Emerson Butler 2018년 10월 30일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by