Problem 47088. Function Call Counter

This problem illustrates advanced use of nested functions and function handles.
Write a function that takes a function handle, F, as input and returns two output arguments, G and C. The first output argument, G, is a function handle that calls F. The second output argument, C, is another function handle that returns the number of times G has been called. Assume that F takes one input argument and returns one output argument.
Example
>> F = @sin;
>> [G,C] = function_call_counter(F);
>> C()
ans = 0
>> G(pi/2)
ans = 1
>> G(-pi/2)
ans = -1
>> G(pi/6)
ans = 0.5000
>> C()
ans = 3

Solution Stats

11.49% Correct | 88.51% Incorrect
Last Solution submitted on Dec 16, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers7

Suggested Problems

More from this Author6

Community Treasure Hunt

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

Start Hunting!