memoize
Add memoization to a function.
📝Syntax
mf = memoize(fh)
📥Input Arguments
Parameter Description
fh function handle to memoize.
📤Output Arguments
Parameter Description
mf MemoizedFunction object that caches the results of fh.
📄Description

memoize returns a MemoizedFunction that caches the outputs of the function handle fh. Calling the returned object with a set of inputs evaluates fh once for those inputs and returns the cached result on later calls with the same inputs. Set the Enabled property to false to bypass the cache, and use clearCache to empty it.

💡Examples
mf = memoize(@(x) x .^ 2);
y = mf(4)
🔗See Also
str2funcfunc2str
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub