Skip to content

Instantly share code, notes, and snippets.

@mpizenberg
Last active January 20, 2017 15:46
Show Gist options
  • Save mpizenberg/bb5eacc211847409cbd9ef38c10256bc to your computer and use it in GitHub Desktop.
Save mpizenberg/bb5eacc211847409cbd9ef38c10256bc to your computer and use it in GitHub Desktop.
Transform a matlab function into a cached function (result stored in a file).
function varargout = cached(cache_filepath, f, varargin )
if exist(cache_filepath, 'file') == 2
load(cache_filepath, 'varargout');
else
[varargout{1:nargout}] = f( varargin{:} );
save(cache_filepath, 'varargout');
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment