WHILE LOOP program does not work
显示 更早的评论
Please, any one tell me why my program does not work, thank you.
This is my program
a=[7 18 11 5;
2 8 10 13;
3 24 20 12;
21 1 20 17];
[m,n]= size(a);
Re=0;
i=1;
while i<=m;
j=1
while j<=n;
if ((a(i,j)<=15) & (a(i,j)>=4))
Re= Re+ a(i,j);
end
end
end
disp(Re)
1 个评论
Walter Roberson
2012-10-24
In order for people to tell you why your program does not work, you have to tell them what the intended working of the program is.
采纳的回答
更多回答(2 个)
You do not increment i or j inside the loops.
i =i+1;
etc. Thus i will always be less than m, and j less than n.
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!