Recall - Recall variable from memory to avoid redundant computations. This function is useful in the following scenario. When processing data in batches, a function is called repeatedly with different parameters. Because not all parameters change every time, some computations may be repeated across successive function calls. For time-consuming computations, (e.g. band-pass filtering of local field potentials) this represents a significant waste of time. Using <a href="matlab:help Store">Store</a> and Recall solves this issue. USAGE x = Recall(name,key1,key2...) name user-defined (arbitrary) name for the variable key1,key2... values of the parameters used to compute the variable EXAMPLE function y = ThetaPhaseLocking(tetrode,cluster,channel) phase = Recall('phase',channel); if isempty(phase), lfp = GetLFP(channel); theta = FilterLFP(lfp,'passband','theta'); phase = Phase(theta); Store(phase,'phase',channel); end ... NOTE Use parsimoniously to avoid saturating memory. SEE See also StartBatch, GetBatch, BatchInfo, CancelBatch, CleanBatches, Store.
0001 function variable = Recall(name,varargin) 0002 0003 %Recall - Recall variable from memory to avoid redundant computations. 0004 % 0005 % This function is useful in the following scenario. When processing data 0006 % in batches, a function is called repeatedly with different parameters. 0007 % Because not all parameters change every time, some computations may be 0008 % repeated across successive function calls. For time-consuming computations, 0009 % (e.g. band-pass filtering of local field potentials) this represents a 0010 % significant waste of time. 0011 % 0012 % Using <a href="matlab:help Store">Store</a> and Recall solves this issue. 0013 % 0014 % USAGE 0015 % 0016 % x = Recall(name,key1,key2...) 0017 % 0018 % name user-defined (arbitrary) name for the variable 0019 % key1,key2... values of the parameters used to compute the variable 0020 % 0021 % EXAMPLE 0022 % 0023 % function y = ThetaPhaseLocking(tetrode,cluster,channel) 0024 % phase = Recall('phase',channel); 0025 % if isempty(phase), 0026 % lfp = GetLFP(channel); 0027 % theta = FilterLFP(lfp,'passband','theta'); 0028 % phase = Phase(theta); 0029 % Store(phase,'phase',channel); 0030 % end 0031 % ... 0032 % 0033 % NOTE 0034 % 0035 % Use parsimoniously to avoid saturating memory. 0036 % 0037 % SEE 0038 % 0039 % See also StartBatch, GetBatch, BatchInfo, CancelBatch, CleanBatches, Store. 0040 % 0041 0042 % Copyright (C) 2011 by Michaƫl Zugaro 0043 % 0044 % This program is free software; you can redistribute it and/or modify 0045 % it under the terms of the GNU General Public License as published by 0046 % the Free Software Foundation; either version 3 of the License, or 0047 % (at your option) any later version. 0048 0049 % (using weird names makes it unlikely that this global could be used somewhere else) 0050 global storage_Store_Recall_981; 0051 0052 variable = []; 0053 0054 stack = dbstack; 0055 if length(stack) < 2, 0056 functionName = 'CommandWindow'; 0057 else 0058 functionName = stack(2).name; 0059 end 0060 0061 try 0062 for i = 1:length(varargin), 0063 x = getfield(storage_Store_Recall_981,functionName,name,['key' int2str(i)]); 0064 if x ~= varargin{i}, return; end 0065 end 0066 variable = getfield(storage_Store_Recall_981,functionName,name,'x'); 0067 catch 0068 return 0069 end