Help with animating a line correctly
조회 수: 5 (최근 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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!