cacheFucntion.m
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.