Home > matlabmk > add_code_info.m

add_code_info

PURPOSE ^

add_code_info() - Reads information about types of stimuli (e.g., the

SYNOPSIS ^

function [new_info, info_names]=add_code_info(code_infofile,blf_ev_num)

DESCRIPTION ^

 add_code_info() - Reads information about types of stimuli (e.g., the
                   length of a stimulus word) 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_code_info(code_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:
   code_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 evcode_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
                        code_infofile. The first column of
                        code_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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005