Gif from subplot not moving

12 Ansichten (letzte 30 Tage)
Jianing Zhang
Jianing Zhang am 5 Okt. 2019
Beantwortet: Walter Roberson am 5 Okt. 2019
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 Kommentare
Walter Roberson
Walter Roberson am 5 Okt. 2019
Unfortunately we need the values of a number of variables in order to test the code.
Jianing Zhang
Jianing Zhang am 5 Okt. 2019
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;

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 5 Okt. 2019
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.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by