Double sigma with exception case

조회 수: 1 (최근 30일)
Kideuk Park 2021년 6월 8일
편집: Joseph Cheng 2021년 6월 8일
I just tried to coding that. but I can not find out how to make double sigma with exception case.
j=/=i means that if j is equal to i, pass that case.
for i=1:3
for j=1:3
if i~=j
phi(i,j)=(((1+(mu(i)/mu(j))))^(1/2)*((M(i)/M(j))^(1/4)))^2/(2*sqrt(2)*(1+(M(i)/M(j)))^(1/2));
phi_sig(i,j)=phi(i,j).*(y(j)/y(i));
else j=j+1;
end
end
phi_sum(i)=sum(phi_sig,'all');
mu_mix(i)=mu(i)./(1+phi_sum(i));
end
mu_sum=sum(mu_mix,'all');
This is original equation for phi.
I tried like this. is it right direction?
댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
David Hill 2021년 6월 8일

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

채택된 답변

Joseph Cheng 2021년 6월 8일
편집: Joseph Cheng 2021년 6월 8일
in your nested forloop you can put a check in for if j==i then continue. you do have a check up there with i~=j which should work but you can get rid of the j=j+1 since the for loop will increment j anyways.
for i = 1:4
for j = 1:4
if j==i
continue
else
disp(sprintf('i= %i and j= %i',i,j))
end
end
end
i= 1 and j= 2 i= 1 and j= 3 i= 1 and j= 4 i= 2 and j= 1 i= 2 and j= 3 i= 2 and j= 4 i= 3 and j= 1 i= 3 and j= 2 i= 3 and j= 4 i= 4 and j= 1 i= 4 and j= 2 i= 4 and j= 3

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by