Explain this while loop
显示 更早的评论
Please explain the steps to how this code fragment works. I don't really understand count or index. Thanks.
What is count as a result of the given Matlab code fragment? Showing your work
may result in partial credit.
numbers = [2 4 3 -5 1 0];
count = 0;
index = 1;
while numbers(index) > 0
count = count + 1;
index = index +1;
end
count = 3
1 个评论
Walter Roberson
2013-2-26
"count" and "index" are just variable names. You could have used XYZ and Chocolate_IceCream instead and MATLAB would not have cared.
采纳的回答
更多回答(1 个)
Youssef Khmou
2013-2-26
编辑:Youssef Khmou
2013-2-26
0 个投票
hi Dave :
Literally " Given a vector of length N, count the number of positive elements before the first negative one, as long as the numbers are positive count them but when a <0 number is met, stop the counting"
类别
在 帮助中心 和 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!