Gif from subplot not moving

12 ビュー (過去 30 日間)
Jianing Zhang
Jianing Zhang 2019 年 10 月 5 日
回答済み: Walter Roberson 2019 年 10 月 5 日
Hi everyone, I'm trying to create a gif of subplots that are changing in value constantly, here is my code
for wt = 0:pi/8:2*pi
v=VO.*exp(-j.*beta.*z).*(1+refl.*exp(2.*j.*beta.*z)).*exp(j*wt);
i=VO.*exp(-j.*beta.*z).*(1-refl.*exp(2.*j.*beta.*z)).*(1/50).*exp(j*wt);
subplot(2,1,1);
plot(z,abs(v))
subplot(2,1,2);
plot(z,abs(i));
filename = 'saved_gif.gif';
del = 0.1; % time between animation frames
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if wt == 0;
imwrite(imind,cm,filename,'gif','Loopcount',inf,'DelayTime',del);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',del);
end
end
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 5 日
Unfortunately we need the values of a number of variables in order to test the code.
Jianing Zhang
Jianing Zhang 2019 年 10 月 5 日
VO=1;
angle = 2*pi*111/360;
refl = 1*exp(angle*1i);
lambda = 0.05;
beta = 2*pi/lambda;
z=-0.15:0.0001:0;

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 10 月 5 日
abs(exp(j*(0:pi/8:2*pi))) are all identical to 1
abs(exp(-j*x)) is exp(imag(x)) and imag() of (0:pi/8:2*pi) is all 0, so that is all exp(0) which is identical to 1.
Your v and i values are all identical except for the exp(j*wt) term that is multiplying them all, so when you take abs() of that and the abs(exp(j*wt)) is always 1, then the abs() is the same for all of your loops. Therefore there is no movement: all of your calculations come out exactly the same.

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by