Hi I have a code like this:
If there any way, that I can avoid for, if else loop? For now the k = 22, but most of the time and i have k closed to 9000+ and it took a lot of computation time. Thanks!
for k=1:22
for j=1:1400
if Ev(k,j)==0 | (((E_beta(k,1)-Ev(k,j))^2)-(0.511^2))<0, p(k,j)=0;
else
p(k,j)=sqrt(((E_beta(k,1)-Ev(k,j))^2)-(0.511^2));
end
end
end

 채택된 답변

Matt J
Matt J 2021년 9월 29일
편집: Matt J 2021년 9월 29일

0 개 추천

D=(E_beta-Ev).^2-0.511^2;
D( D<0 | ~Ev)=0;
p=sqrt(D);

댓글 수: 2

Hokkien
Hokkien 2021년 9월 29일
Hi Matt tahnk you! By the way, what's the meaning for ~Ev?
Matt J
Matt J 2021년 9월 29일
You're welcome, but pleae Accept-click the answer if it does what you need.
~Ev is the same thing as Ev==0.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2021년 9월 29일

댓글:

2021년 9월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by