WHILE LOOP program does not work
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
채택된 답변
Image Analyst
2012년 10월 25일
Try it without loops, in a more MATLAB-ish vectorized way:
indexesToSum = a>=4 & a<=15
Re = sum(a(indexesToSum))
참고 항목
카테고리
Help Center 및 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!