cacheFucntion.m

Function which caches the output of other functions.
210 Downloads
Updated 19 Dec 2013

View License

Imagine you have a long-running function:

[out1,out2,out3,...] = longRunning(arg1,arg2,arg3,...)

and this function is being run many times with the same inputs. If you change this to:

[out1,out2,out3,...] = cacheFunction(@longRunning,arg1,arg2,arg3,...)

then only the first instance will run long, further calls will be grabbed from a global variable 'functionCache'. This only recaculates results when the inputs change.

Thanks to Christopher Wipf for most of the code.

Cite As

Nicolas Smith (2024). cacheFucntion.m (https://www.mathworks.com/matlabcentral/fileexchange/44650-cachefucntion-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Scope Variables and Generate Names in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.1.0.0

uses func2str to get the function name.

1.0.0.0