Created
September 7, 2015 11:19
-
-
Save MarkRedeman/6569b3c7bcc8d5f32822 to your computer and use it in GitHub Desktop.
This function takes a function and returns a function that counts how many times the function has been called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% make_counting_function: | |
function [g] = make_counting_function(f) | |
count = 0; | |
function [varargout] = counting_function(varargin) | |
if (nargin == 0) | |
varargout = {count}; | |
else | |
count = count + 1; | |
varargout = {f(varargin{:})}; | |
end | |
end | |
g = @counting_function; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment