How we can display images at different times by using for loop instead of following program and how we can make movie from following program?
3 views (last 30 days)
Show older comments
- clear all;
- clc;
- close all;
- dim=32;
- [kx,ky]=meshgrid(-3:6/(dim-1):3);
- circ=sqrt(kx.^2+ky.^2)<1;
- r=sqrt(kx.^2+ky.^2);
- alp=asin(0.95);
- k0=1/sin(alp);
- k=256;
- kz=sqrt(k0^2-(kx.^2+ky.^2));
- Gx=-1i*sqrt(k0./kz).*((k0*ky.^2+kz.*kx.^2)./(k0*(kx.^2+ky.^2)));
- Gy=1i*sqrt(k0./kz).*((kz-k0).*kx.*ky)./(k0*(kx.^2+ky.^2));
- Gz=1i*sqrt(k0./kz).*(kx./k0);
- Fx=1i*sqrt(k0./kz).*((kz-k0).*kx.*ky)./(k0*(kx.^2+ky.^2));
- Fy=-1i*sqrt(k0./kz).*((k0*kx.^2+kz.*ky.^2)./(k0*(kx.^2+ky.^2)));
- Fz=1i*sqrt(k0./kz).*(ky./k0);
- ph=(atan2(kx,ky)+pi);
- ph=rot90(ph,3);
- la=-sin(ph);
- lb=rot90(cos(ph),3);
- z=-128:1:127;
- c = numel(z);
- mz=(pi/(3*8*2*tan(alp/2)));
- n = size(kx);
- Ex = zeros([k k c]);
- Ey = zeros([k k c]);
- Ez = zeros([k k c]);
- for jj=1:c
- Ex(:,:,jj)=fftshift(fft2(exp(1i*kz*mz*z(jj)).*(Gx.*la.*circ)-rot90(exp(1i*kz*mz*z(jj)).*Gy.*lb.*circ,3),k,k));
- Ey(:,:,jj)=fftshift(fft2(exp(1i*kz*mz*z(jj)).*(Gy.*la.*circ)+rot90(exp(1i*kz*mz*z(jj)).*Gx.*lb.*circ,3),k,k));
- Ez(:,:,jj)=fftshift(fft2(exp(1i*kz*mz*z(jj)).*(Gz.*la.*circ)+rot90(exp(1i*kz*mz*z(jj)).*Gz.*lb.*circ,3),k,k));
- end
- Ex=Ex(k/2,:,:);
- Ey=Ey(k/2,:,:);
- Ez=Ez(k/2,:,:);
- Ex=squeeze(Ex);
- Ey=squeeze(Ey);
- Ez=squeeze(Ez);
- Ix=Ex.*conj(Ex);
- Iy=Ey.*conj(Ey);
- Iz=Ez.*conj(Ez);
- I=Ix+Iy+Iz;
- t=0;
- I1=((I).*exp(1i*pi*t));
- t=(2/7);
- I2=((I).*exp(1i*pi*t));
- t=(2*2/7);
- I3=((I).*exp(1i*pi*t));
- t=(3*2/7);
- I4=((I).*exp(1i*pi*t));
- t=(4*2/7);
- I5=((I).*exp(1i*pi*t));
- t=(5*2/7);
- I6=((I).*exp(1i*pi*t));
- t=(6*2/7);
- I7=((I).*exp(1i*pi*t));
- t=7*2/7;
- I8=((I).*exp(1i*pi*t));
- figure(7)
- subplot(2,4,1);imagesc(I1.*conj(I1)),colormap gray;axis image;axis off
- subplot(2,4,2);imagesc(I2.*conj(I2)),colormap gray;axis image;axis off
- subplot(2,4,3);imagesc(I3.*conj(I3)),colormap gray;axis image;axis off
- subplot(2,4,4);imagesc(I4.*conj(I4)),colormap gray;axis image;axis off
- subplot(2,4,5);imagesc(I5.*conj(I5)),colormap gray;axis image;axis off
- subplot(2,4,6);imagesc(I6.*conj(I6)),colormap gray;axis image;axis off
- subplot(2,4,7);imagesc(I7.*conj(I7)),colormap gray;axis image;axis off
- subplot(2,4,8);imagesc(I8.*conj(I8)),colormap gray;axis image;axis o
- % % movie(F(t))
# I what to two display time dependence image of I by using for loop and how we can make movie from this time dependence of I.
# how we get all images at all times;
# by using for loop t=0:2/7:2;
# if anyone help me in this regard it is great help for me
# thanks in advance,
2 Comments
Walter Roberson
on 3 Apr 2013
Those decimal numbers at the beginning of every line are going to cause syntax errors.
Image Analyst
on 3 Apr 2013
Yeah, makes it so much of a pain to fix that I'm not even going to attempt to copy and paste this into MATLAB. I suggest the author read this tutorial on how to put code in so that we can copy and paste it, as well as read it: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Answers (1)
Image Analyst
on 3 Apr 2013
I can't run your code, so all I can suggest is the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_a_movie_from_my_MATLAB_figures.3F and to put in a "drawnow" in the loop to force it to update/refresh the display immediately instead of waiting until it gets around to it or finishes the loop.
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!