%% Disable Memoization
% In your current working folder, create the following file memoizeSquareExample.m that contains a function to compute the square of a number. When the function is called, if MATLAB returns cached results, msg is not displayed.

type memoizeSquareExample.m

% Memoize the function.  By default, memoization is enabled.

mf = memoize(@memoizeSquareExample);

% Call the memoized function twice with the same input value.  msg is displayed only once because the second function call returns cached results.

a = mf(42);
b = mf(42);

% Disable memoization and call the memoized function with a repeat input value. Although the results for an input of 42 are cached, msg is displayed because memoization is disabled.

mf.Enabled = false;
c = mf(42);

% Call the memoized function with a different set of inputs.

d = mf(13);

% Call the stats function to investigate the cached results. MATLAB does not return cached results while memoization is disabled or collect statistics, it continues to store input and output values.

s = mf.stats();
s.Cache.Inputs{:}

% Copyright 2012 The MathWorks, Inc.