cacheFucntion.m
Version 1.1.0.0 (1.52 KB) by
Nicolas Smith
Function which caches the output of other functions.
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 .
MATLAB Release Compatibility
Created with
R2010a
Compatible with any release
Platform Compatibility
Windows macOS LinuxCategories
Find more on Scope Variables and Generate Names in Help Center and MATLAB Answers
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
