help: how to simplify many many "elseif" loops?# Computation - 科学计算
g*s
1 楼
for n2=1:pixels
for n1=1:pixels
r=sqrt((n1-pixels/2)^2+(n2-pixels/2)^2)*lenssize/pixels;
if r tobeknown(n1,n2)=pi;
elseif r tobeknown(n1,n2)=0;
elseif r tobeknown(n1,n2)=pi;
elseif r tobeknown(n1,n2)=0;
.........
else if r tobeknown(n1,n2)=pi;
else
tobeknown(n1,n2)=0;
end
end
end
for n1=1:pixels
r=sqrt((n1-pixels/2)^2+(n2-pixels/2)^2)*lenssize/pixels;
if r
elseif r
elseif r
elseif r
.........
else if r
else
tobeknown(n1,n2)=0;
end
end
end