Write a function that returns a function that counts the number of times it is invoked. Example:

>> h = counter;
>> h()
ans =
     1
>> h()
ans =
     2
>> h()
ans =
     3

Note: your solution cannot use persistent variables.

Solution Stats

897 Solutions

103 Solvers

Last Solution submitted on Apr 22, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers103

Suggested Problems

More from this Author2

Problem Tags

Community Treasure Hunt

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

Start Hunting!