eeg_toolbox_recent - Keep track of eeg_toolbox .mat files Useage: [files,p] = eeg_toolbox_recent([filename],[command]) filename = path & filename of an eeg_toolbox .mat file to be added to the recent files list command = 'load', to load one of the recent files 'clear', to clear all recent files If filename is not given, the function returns the most recent files saved (if any). If it is given, the filename is added to the list. If the load command is given, filename.mat is loaded and the p struct is returned. Otherwise the p struct is empty. Tracks recent p structure saves to .mat files for the eeg_toolbox gui. The return variable 'files' is a cell array of strings containing the filesystem location of recent p files saved. The recent files list is limited to 20.
0001 function [ files, varargout ] = eeg_toolbox_recent(filename,command); 0002 0003 % eeg_toolbox_recent - Keep track of eeg_toolbox .mat files 0004 % 0005 % Useage: [files,p] = eeg_toolbox_recent([filename],[command]) 0006 % 0007 % filename = path & filename of an eeg_toolbox .mat file to 0008 % be added to the recent files list 0009 % command = 'load', to load one of the recent files 0010 % 'clear', to clear all recent files 0011 % 0012 % If filename is not given, the function returns 0013 % the most recent files saved (if any). If it 0014 % is given, the filename is added to the list. 0015 % 0016 % If the load command is given, filename.mat is 0017 % loaded and the p struct is returned. Otherwise 0018 % the p struct is empty. 0019 % 0020 % Tracks recent p structure saves to .mat files 0021 % for the eeg_toolbox gui. The return variable 0022 % 'files' is a cell array of strings containing 0023 % the filesystem location of recent p files saved. 0024 % 0025 % The recent files list is limited to 20. 0026 % 0027 0028 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $ 0029 0030 % Licence: GNU GPL, no express or implied warranties 0031 % Created: 02/2002 Darren.Weber_at_radiology.ucsf.edu 0032 % 0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0034 0035 0036 LIMIT = 20; 0037 0038 if ~exist('filename','var'), 0039 filename = ''; 0040 elseif isempty(filename), 0041 filename = ''; 0042 end 0043 if ~exist('command','var'), 0044 command = ''; 0045 elseif isempty(command), 0046 command = ''; 0047 end 0048 0049 0050 % -- locate the installation path and the recent file list 0051 0052 path = fileparts(which('eeg_toolbox_recent')); 0053 if isempty(path), 0054 msg = sprintf('Cannot find eeg_toolbox on the matlab path.\n\nPlease use the addpath command.\n\n'); 0055 error(msg); 0056 else 0057 path = strcat(path,filesep); 0058 end 0059 0060 0061 % -- load the recent 'files' cell array 0062 0063 recentfile = strcat(path,'eeg_toolbox_recent.mat'); 0064 if exist(recentfile) == 2, 0065 load(recentfile); 0066 else 0067 files = cell(1); 0068 end 0069 0070 0071 % -- add a new file to the 'files' array 0072 0073 if ~isempty(filename), 0074 if isempty(files{1}), 0075 files{1} = filename; 0076 else 0077 % should check to see if already in list 0078 % if so, rearrange the list 0079 0080 i = strmatch(filename,char(files),'exact'); 0081 if ~isempty(i), 0082 % remove it from current list 0083 if isequal(i,1), files = files(2:end); 0084 elseif isequal(i,LIMIT), files = files(1:end-1); 0085 else files = files([1:i-1 i+1:end]); 0086 end 0087 end 0088 files = fliplr(files); % put most recent at end, for now 0089 files{end+1} = filename; % add filename to end 0090 files = fliplr(files); % now put most recent at beginning 0091 0092 end 0093 0094 % only keep 'LIMIT' most recent 0095 if size(files,2) > LIMIT, 0096 files = files(1:LIMIT); 0097 end 0098 0099 save(recentfile,'files'); 0100 end 0101 0102 0103 switch command, 0104 case 'load', 0105 if ~isempty(filename), 0106 [p] = []; 0107 load(filename); 0108 end 0109 case 'clear', 0110 files = cell(1); 0111 save(recentfile,'files'); 0112 otherwise, 0113 end 0114 0115 0116 0117 if (nargout > 1) & exist('p','var'), 0118 if ~isempty(p), 0119 varargout{1} = p; 0120 end 0121 end 0122 0123 0124 0125 return