Help with animating a line correctly
3 ビュー (過去 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!