g******s 发帖数: 733 | 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 | c****r 发帖数: 185 | 2 something like this:
for j=1:10
if r>=bcdn(j) and r < bcdn(j+1) ...
【在 g******s 的大作中提到】 : 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
| c****r 发帖数: 185 | 3 If n>>10, then one should use binary search.
For the second issue, change the loop body as
if r>=bcdn(j) then store j to a variable
and break the loop. |
|