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 CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by