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!