Make a function for a counter
显示 更早的评论
I have to make a function which produces a counter. It takes an input which can be a vector of any length and produces a counter as the output which is upto the limit of the input vector. Im assuming since we dont know the no of loops we might use the while loop for this but im not sure how to proceed. Any suggestions?
1 个评论
Daniell Algar
2013-5-12
I don't understand your question... Can you give an example of input and desired output?
回答(1 个)
Image Analyst
2013-5-12
What is it counting? Is there also an input which is the current count, and that has to be incremented, but has a limit of the max value of the input vector?
function newCount = MyCounter(oldCount, inputArray)
maxCount = max(inputArray(:));
newCount = min([oldCount+1, maxCount]);
类别
在 帮助中心 和 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!