HOW TO GET TOTAL DATA FROM FOR LOOP?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have problem in following code, I am saving for loop data using the following method(matrix method) but it is lengthy, but I require easy method to save for loop data, can anyone help me in this regard
clearall;
clc;
dim=32;
[kx,ky]=meshgrid(-1:2/(dim-1):1,-1:2/(dim-1):1);
circ=sqrt(kx.^2+ky.^2)<1;
kx=kx/2;
ky=ky/2;
alp=asin(1);
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=-32:1:32;
[r,c]=size(z);
mz=0.5;
for j=1:c
Ex(:,:,j)=fftshift(fft2(exp(i*kz*z(j)*mz).*(Gx).*circ,k,k));
Ix(:,:,j)=Ex(:,:,j).*conj(Ex(:,:,j));
Ey(:,:,j)=fftshift(fft2((exp(i*kz*z(j)*mz).*Gy).*circ,k,k));
Iy(:,:,j)=Ey(:,:,j).*conj(Ey(:,:,j));
Ez(:,:,j)=fftshift(fft2((exp(i*kz*z(j)*mz).*Gz).*circ,k,k));
Iz(:,:,j)=Ez(:,:,j).*conj(Ez(:,:,j));
I=Ix+Iy+Iz;
M=I(k/2,:,:);
end
M1=[M(:,:,1);M(:,:,2);M(:,:,3);M(:,:,4);M(:,:,5);M(:,:,6);M(:,:,7);M(:,:,8);M
(:,:,9);M(:,:,10);M(:,:,11);M(:,:,12);M(:,:,13); M(:,:,14);M(:,:,15);
M(:,:,16);M(:,:,17); M(:,:,18);M(:,:,19);M(:,:,20);M
(:,:,21);M(:,:,22);M(:,:,23);M(:,:,24);M(:,:,25);
M(:,:,26);M(:,:,27);M(:,:,28);M(:,:,29);M(:,:,30);M(:,:,31);M(:,:,32);
M(:,:,33);M(:,:,34);M(:,:,35);M(:,:,36);M(:,:,37);
M(:,:,38);M(:,:,39);M(:,:,40);M(:,:,41);M(:,:,42);M(:,:,43);M(:,:,44);
M(:,:,45);M(:,:,46);M(:,:,47); M(:,:,48);M(:,:,49);
M(:,:,50);M(:,:,51);M(:,:,52);M(:,:,53);M(:,:,54);M(:,:,55);M(:,:,56);
M(:,:,57); M(:,:,58);M(:,:,59);M(:,:,60);M(:,:,61);
M(:,:,62);M(:,:,63);M(:,:,64);M(:,:,65)];
thanks in advance;
0 Kommentare
Antworten (1)
Andrei Bobrov
am 17 Sep. 2012
Bearbeitet: Andrei Bobrov
am 17 Sep. 2012
try this ( EDIT )
dim=32;
[kx,ky]=meshgrid(-1:2/(dim-1):1);
circ=sqrt(kx.^2+ky.^2)<1;
kx=kx/2;
ky=ky/2;
alp=asin(1);
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=-32:1:32;
c = numel(z); %[r,c]=size(z);
mz=0.5;
n = size(kx);
Ex = zeros([k k c]);
Ey = zeros([k k c]);
Ez = zeros([k k c]);
q1 = exp(1i*kz*mz);
for jj=1:c
q2 = q1.^z(jj).*circ;
Ex(:,:,jj)=fftshift(fft2(q2.*Gx,k,k));
Ey(:,:,jj)=fftshift(fft2(q2.*Gy,k,k));
Ez(:,:,jj)=fftshift(fft2(q2.*Gz,k,k));
end
I = Ex.*conj(Ex) + Ey.*conj(Ey) + Ez.*conj(Ez);
M=I(k/2,:,:);
Mout = squeeze(M).';
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!