Call the memoized function several times. The first time you call the function with a particular set of inputs, MATLAB caches the results.
a = mf(13,42); % calls plus; caches results
b = mf(7,33); % calls plus; caches results
c = mf(13,42); % does not call plus; returns cached results
d = mf(5,120); % calls plus; caches results
e = mf(13,42); % does not call plus; returns cached results
f = mf(7,33); % does not call plus; returns cached results
Call the stats function.
s = stats(mf)
s = struct with fields:
Cache: [1x1 struct]
MostHitCachedInput: [1x1 struct]
CacheHitRatePercent: 50
CacheOccupancyPercent: 30
Determine which sets of inputs you used the most.
s.MostHitCachedInput
ans = struct with fields:
Hits: 2
Input: {[13] [42]}
MemoizedFunction statistics, returned as
a structure containing these fields.
Field
Description
Cache
Cached results, returned as a structure. If m is
the number of function calls with cached results, then the structure
contains the following fields:
Inputs – Cached input values,
returned as a 1-by-m cell array.
Each element in the Inputs cell array is a 1-by-n cell
array, where n is the number of inputs for a particular
function call.
Outputs – Cached output
values, returned as a 1-by-m cell
array. Each element in the Outputs cell array is
a 1-by-p cell array, where p is
the number of outputs for a particular function call.
HitCount – Number of times
each cached set of input values was accessed, returned as 1-by-mdouble array.
TotalHits – Total number
of times a set of input values was found in the cache, returned as
a double.
TotalMisses – Total number
of times a set of input values was not found in the cache, returned
as a double.
MostHitCachedInput
Inputs for the most accessed cached values, returned
as a structure. The structure contains the following fields:
Hits – Number of times the
cached values were accessed, returned as an integer
Input – Input values for
the most accessed cached values, returned as a cell array of input
values
CacheHitRatePercent
Percentage of times an input was found in the cache,
returned as a double. This property is computed by (TotalHits/(TotalHits+TotalMisses))*100.
CacheOccupancyPercent
How full the cache is, returned as a double representing
a percentage. This property is computed by (Number of cache
entries/cache size)*100.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.