Skip to content

Instantly share code, notes, and snippets.

@MarkRedeman
Created September 7, 2015 11:19
Show Gist options
  • Save MarkRedeman/6569b3c7bcc8d5f32822 to your computer and use it in GitHub Desktop.
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.
%% 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