Redian新闻
>
help: how to simplify many many "elseif" loops?
avatar
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 rtobeknown(n1,n2)=pi;
elseif rtobeknown(n1,n2)=0;
elseif rtobeknown(n1,n2)=pi;
elseif rtobeknown(n1,n2)=0;
.........
else if rtobeknown(n1,n2)=pi;
else
tobeknown(n1,n2)=0;
end
end
end
avatar
c*r
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
avatar
c*r
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.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。