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
Daniell Algar 2013년 5월 12일
I don't understand your question... Can you give an example of input and desired output?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 5월 12일

0 개 추천

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에 대해 자세히 알아보기

질문:

2013년 5월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by