Multiple if condition inside multiple for loops
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!