필터 지우기
필터 지우기

Multiple if condition inside multiple for loops

조회 수: 1 (최근 30일)
chhatra pal
chhatra pal 2019년 12월 1일
답변: chhatra pal 2019년 12월 2일
hi I am having some problems. I need to apply 3 conditions simultaneously. but I don't understand that it is correct or not. I am attaching the data files and matlab code which I wrote. Can anybody help please .Please check if statement. Actually I want to find indices 'k' and 'm' with the condition 'k<m' and then use these indices in computation of our main variable u_c.
%%%% Construction of U
u_c(1)=u(1); u_c(N+1)=u(N+1);
for i=2:N
for m=2:N
for k=2:N
if (((z(k-1)+z(k))/2)<((x(i-1)+x(i))/2)<((z(k+1)+z(k))/2))&&...
(((z(m-1)+z(m))/2)<((x(i+1)+x(i))/2)<((z(m+1)+z(m))/2))&&(k<m)
s_c=0;
for j=k+1:m-1
s_c=s_c+(hnold(j)*u(j));
end
s_c;
u_c(i)=(1/hn(i))*((((z(k+1)+z(k))/2-(x(i-1)+x(i))/2)*u(k))+...
(((-z(m-1)+z(k))/2+(x(i+1)+x(i))/2)*u(m))+s_c);
elseif (((z(m-1)+z(m))/2)<((x(i-1)+x(i))/2)<((z(m+1)+z(m))/2))&&...
(((z(m-1)+z(m))/2)<((x(i+1)+x(i))/2)<((z(m+1)+z(m))/2))
u_c(i)=u(m);
end
break
end
end
break
end
  댓글 수: 1
Vladimir Sovkov
Vladimir Sovkov 2019년 12월 1일
At the first glance, the "if" statements look correct (if only all the parenthesis are correctly paired). However, thanks to the "break" statements, your program will always deal with k=2 and n=2 alone, nothing else.

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

답변 (1개)

chhatra pal
chhatra pal 2019년 12월 2일
Thanks Prof. Vladimir Sovkov

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by