there is an error in describing the loop, please help me to resolve this one.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clear
x = linspace (-1,1,256);
y = linspace (-1,1,256);
[X,Y] = meshgrid(x,y);
r = sqrt(X.^2 + Y.^2);
z= 0;
w = 100;
E0 = 1;
O = rand(256,256);
E = E0*exp(-1i*(O));
A = (abs(E)).^2 ;
x=linspace(-1,1,256);
[X,Y]=meshgrid(x,x);
r=sqrt(X.^2+Y.^2);
R= 0.06;
t = 0.5;
l= 0:36:360;
M = cell(1,length(l));
for i = 1:length(l)
h= t*cosd(l(i));k= t*sind(l(i));
p=sqrt((X-h).^2+(Y-k).^2);
M{i}=(p<R);
end
M = M{1}+M{2}+M{3}+M{4}+M{5}+M{6}+M{7}+M{8}+M{9}+M{10};
Io=1.0;
Y=linspace(1,-1,256); Z=Y ;
A(1:length(Y),1:length(Z))=0;
for i=1:length(Y)
for j=1:length(Z)
q=(Y(i).^2+Z(j).^2).^0.5;
w = 0.3;
A(i,j)=Io.*exp(-((q.^2)./w^2));
end
end
G0 = 15;
I = 1;
E = E0*exp(-1i*(O));
for i = 1:100
G(i) = G0/(1+ (abs(E(i)))^2/I);
E(i+1) = M *(ifft(A*(fft(G* E(i)))));
end
imagesc(E)
3 commentaires
Rik
le 30 Août 2022
So the question is: what do you want to do?
Answering that question is very hard because you chose non-descriptive variable names and didn't write any comments. How do you expect anyone to understand what is going on in your code? Remember that you in three months time are a different person from current you. How is future you suposed to understand what you did and extend functionality or fix a bug?
Réponse acceptée
Rik
le 30 Août 2022
Modifié(e) : Rik
le 30 Août 2022
If you're not planning to do anything with the intermediate values, why would you store them?
init % Runs the first part of your code.
G0 = 15;
I = 1;
E = E0*exp(-1i*(O));
for iteration=1:10
G = G0./(1+ (abs(E))^2/I);
E = M *(ifft(A*(fft(G* E))));
end
imagesc((abs(E)).^2);colorbar
If you want to store the intermediate numbers, that is also possible: use cell vectors. That will you give more intutive control. Just remember that Matlab uses 1-indexing, not 0-indexing.
G0 = 15;
I = 1;
E = { E0*exp(-1i*(O)) };
G = { G0./(1+ (abs(E{1}))^2/I) };
for ind=2:10
E{ind} = M *(ifft(A*(fft(G{ind-1}* E{ind-1}))));
G{ind} = G0./(1+ (abs(E{ind}))^2/I);
end
E_final = M *(ifft(A*(fft(G{10}* E{10}))));
imagesc((abs(E_final)).^2);colorbar
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!