add_ev_info() - Reads information about log events (e.g., if a stimulus was accurately recalled by the participant after the experiment) from a text file and stores the information as a matrix that can be easily added to existing epoch information in the function crw2set.m. Usage: >> [new_info, info_names]=add_ev_info(event_infofile,blf_ev_num) Required Global Variable: VERBLEVEL = matlabMK level of verbosity (i.e., tells functions how much to report about what they're doing during runtime) Inputs: event_infofile = a space or tab delimited text file containing additional NUMERIC information about log events. The first row of the file is a header line with a one word description of each column in the file. Each row below the headerline corresponds to a different log event. The first column of the file specifies the log event number. Additional columns specificy numeric event information (e.g., a binary variable indicating if the item was subsquently recalled, the participant's estimate of how probable that stimulus was). To import non-numeric information use logitem_info2set.m. blf_ev_num = a vector of log event numbers indicating which row of the matrix of blf event information (from the parent function) corresponds to which log event. Outputs: new_info = a matrix of new event information that can be appended to the existing blf info matrix info_names = a cell array of strings containing the header information for each column of event_infofile. The first column of event_infofile is ignored since the log event numbers are already in the blf info matrix. Additional Notes: Don't use parenthesis in column header names. Matlab interprets the name as a function call. Use NaN to fill cells for codes that don't have a value for a particular column Author: David Groppe Kutaslab, 8/2009
0001 function [new_info, info_names]=add_ev_info(event_infofile,blf_ev_num) 0002 % add_ev_info() - Reads information about log events (e.g., if a stimulus 0003 % was accurately recalled by the participant after the 0004 % experiment) from a text file and stores the information 0005 % as a matrix that can be easily added to existing epoch 0006 % information in the function crw2set.m. 0007 % 0008 % Usage: 0009 % >> [new_info, info_names]=add_ev_info(event_infofile,blf_ev_num) 0010 % 0011 % Required Global Variable: 0012 % VERBLEVEL = matlabMK level of verbosity (i.e., tells functions 0013 % how much to report about what they're doing during 0014 % runtime) 0015 % Inputs: 0016 % event_infofile = a space or tab delimited text file 0017 % containing additional NUMERIC 0018 % information about log events. The first 0019 % row of the file is a header line with a 0020 % one word description of each column in the 0021 % file. Each row below the headerline 0022 % corresponds to a different log event. The 0023 % first column of the file specifies the log 0024 % event number. Additional columns 0025 % specificy numeric event information (e.g., 0026 % a binary variable indicating if the item 0027 % was subsquently recalled, the 0028 % participant's estimate of how probable 0029 % that stimulus was). To import non-numeric 0030 % information use logitem_info2set.m. 0031 % blf_ev_num = a vector of log event numbers indicating 0032 % which row of the matrix of blf event 0033 % information (from the parent function) 0034 % corresponds to which log event. 0035 % 0036 % Outputs: 0037 % new_info = a matrix of new event information that can 0038 % be appended to the existing blf info 0039 % matrix 0040 % info_names = a cell array of strings containing the 0041 % header information for each column of 0042 % event_infofile. The first column of 0043 % event_infofile is ignored since the log 0044 % event numbers are already in the blf info matrix. 0045 % 0046 % 0047 % Additional Notes: 0048 % 0049 % Don't use parenthesis in column header names. Matlab interprets 0050 % the name as a function call. 0051 % 0052 % Use NaN to fill cells for codes that don't have a value for a 0053 % particular column 0054 % 0055 % Author: 0056 % David Groppe 0057 % Kutaslab, 8/2009 0058 0059 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%% 0060 % 0061 % 10/07/09 Function provides a warning if it detects an attempt to import 0062 % non-numeric values. Non-numeric values should appear as NaN in new_info. 0063 % 0064 0065 global VERBLEVEL 0066 0067 new_info=[]; 0068 info_names=[]; 0069 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0070 % LOAD INFORMATION ABOUT EACH LOG EVENT FROM A TEXT FILE 0071 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0072 VerbReport(sprintf('Getting additional information about log events from %s', ... 0073 event_infofile), 1, VERBLEVEL); 0074 [ev_fid, message]=fopen(event_infofile,'r'); 0075 if (ev_fid==-1) 0076 fprintf('*************** ERROR ******************\n'); 0077 fprintf('Cannot open file %s.\n',event_infofile); 0078 fprintf('According to fopen: %s.\n',message); 0079 fprintf('Aborting import of additional log event information.\n'); 0080 file_ev_info=[]; 0081 else 0082 %read column headers 0083 txtline = []; 0084 txtline = fgetl(ev_fid); 0085 if (txtline==-1) 0086 fprintf('*************** ERROR ******************\n'); 0087 fprintf('File %s is empty.\n',ev_fid); 0088 fprintf('Aborting import of additional log event information.\n'); 0089 file_ev_info=[]; 0090 else 0091 0092 %Read column header 0093 clear ev_col_hdrs; 0094 [ev_col_hdrs{1}, rmndr]=strtok(txtline); 0095 col_ct=1; 0096 fprintf('Event number column is: %s\n',ev_col_hdrs{1}); 0097 while ~isempty(rmndr) 0098 col_ct=col_ct+1; 0099 [ev_col_hdrs{col_ct}, rmndr]=strtok(rmndr); 0100 fprintf('Column %d is: %s\n',col_ct,ev_col_hdrs{col_ct}); 0101 end 0102 0103 %Read event information 0104 row_ct=1; 0105 while ~feof(ev_fid) 0106 txtline = fgetl(ev_fid); 0107 col_ct=1; 0108 while ~isempty(txtline) 0109 [neo_val, txtline]=strtok(txtline); 0110 file_ev_info(row_ct,col_ct)=str2double(neo_val); %events that 0111 %do not have a value for that column should be represented as NaN 0112 if isempty(str2num(neo_val)) 0113 watchit(sprintf(['Event info file %s appears to have a non-numeric entry at Row #%d, Column %s.\n', ... 0114 'When using crw2set only numeric values are permitted. Use logitem_info2set.m for non-numeric values.'], ... 0115 event_infofile,row_ct+1,ev_col_hdrs{col_ct})); 0116 end 0117 col_ct=col_ct+1; 0118 end 0119 row_ct=row_ct+1; 0120 end 0121 0122 %Check to make sure each event only occurs once: 0123 [uni, uni_id]=unique(file_ev_info(:,1),'first'); %First column is 0124 %assumed to be the log event number 0125 if length(uni)~=size(file_ev_info,1), 0126 fprintf('*************** ERROR ******************\n'); 0127 fprintf('add_ev_info.m: Your file %s has the same ',event_infofile); 0128 fprintf('event on multiple rows.\n'); 0129 fprintf('All the information for a single event should '); 0130 fprintf('be on one row.\n'); 0131 fprintf(['Only the topmost row for each event will be' ... 0132 ' imported.\n']); 0133 fprintf('Additional rows for an event will be ignored.\n'); 0134 file_ev_info=file_ev_info(uni_id,:); 0135 end 0136 0137 %%%Add event info to existing epoch information 0138 n_ev=length(blf_ev_num); 0139 0140 %If an event isn't listed in this file, it will have NaN values 0141 new_info=zeros(n_ev,size(file_ev_info,2)-1)*NaN; 0142 ct=0; 0143 for dg=file_ev_info(:,1)', 0144 ct=ct+1; 0145 id=find(blf_ev_num==dg); 0146 new_info(id,:)=file_ev_info(ct,2:end); %first col ignored 0147 %because it's just the 0148 %event number 0149 end 0150 0151 %return all header names except for the first column 0152 clear info_names; 0153 for dg=1:(length(ev_col_hdrs)-1), 0154 info_names{dg}=ev_col_hdrs{dg+1}; 0155 end 0156 end 0157 fclose(ev_fid); 0158 end 0159