how to perform for loop;

1 次查看(过去 30 天)
MOHD
MOHD 2012-12-5
dim=64;
[kx,ky]=meshgrid(-1:2/(dim-1):1);
circ=sqrt(kx.^2+ky.^2)<1;
kx=kx/2;
ky=ky/2;
alp=asin(0.8);
k0=1/sin(alp);
k=256;
kz=sqrt(k0^2-(kx.^2+ky.^2));
Gx=sqrt(k0./kz).*((k0*ky.^2+kz.*kx.^2)./(k0*(kx.^2+ky.^2)));
Gy=sqrt(k0./kz).*((kz-k0).*kx.*ky)./(k0*(kx.^2+ky.^2));
Gz=sqrt(k0./kz).*(kx./k0);
z=-64:1:63;
[r,c]=size(z);
mz=pi*64/(256);
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*z(jj)*mz).*Gx.*circ,k,k));
Ey(:,:,jj)=fftshift(fft2(exp(1i*kz*z(jj)*mz).*Gy.*circ,k,k));
Ez(:,:,jj)=fftshift(fft2(exp(1i*kz*z(jj)*mz).*Gz.*circ,k,k));
end
I =Ex.*conj(Ex)+Ey.*conj(Ey)+Ez.*conj(Ez);
M=I(k/2,:,:);
M1=squeeze(M).';
figure(1)
imagesc((M1));colormap gray
I have problem to perform for loop operation, I used above method to perform
for loop operation. Can anyone help me to perform this for loop operation in
other method it will be great helpfor me
thanking you in advance for your kind help
  1 个评论
per isakson
per isakson 2012-12-5
Your script runs here (R2012a, 64bit, Windows7) and produces an image. I cannot see any problem.
Do you get a warning or error message? You need to be more specific.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by