cacheFucntion.m

Function which caches the output of other functions.

You are now following this Submission

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 (2026). cacheFucntion.m (https://www.mathworks.com/matlabcentral/fileexchange/44650-cachefucntion-m), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Scope Variables and Generate Names in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0.0

uses func2str to get the function name.

1.0.0.0