Home > matlabmk > import_rts.m

import_rts

PURPOSE ^

rt_vector() - import cdbl generated rt information about events

SYNOPSIS ^

function [rtmsec, rtbins, rtvector]=import_rts(rtfile,blf_evnum)

DESCRIPTION ^

 rt_vector() - import cdbl generated rt information about events
             listed in blf file 
              
 Usage:
  >> rt_vector=import_rts(rtfile,blf_evnum)


 Global Variable:
   VERBLEVEL = crw2set level of verbosity (i.e., tells functions
               how much to report about what they're doing during runtime)


 Inputs:
   rtfile     = name of cdbl generated rt file (a string)
   blf_evnum  = a vector of log item integers for all events that
                are listed in the corresponding blf file.

 Outputs:

   rtmsec   = a cell array with one entry for each blf item. Each cell of the
               array stores a reaction time (in milliseconds) for each bin
               that item falls in (this way the same item can have different
               RTs depending on which bin it's being considered as).
   rtbins   = a cell array with one entry for each blf item. Each cell of
               the array indicates which bin the corresponding reaction time 
               in rtmsec belongs to. 
   rtvector = a vector of reaction times (in msec). The nth element
               of rt_vector corresponds to the nth element of
               blf_evnum.  If an element of blf_evnum does not have
               a reaction time listed in rtfile, the corresponding
               element of rt_vector is NaN.  This can be used to create a
               field in EEG.epoch (which makes it easier to access RTs via
               the EEGLAB GUI). However, if a single blf item has more than
               one RT, you can't use this option and it will be empty.
      
 Author:
 David Groppe
 Kutaslab, 8/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [rtmsec, rtbins, rtvector]=import_rts(rtfile,blf_evnum)
0002 % rt_vector() - import cdbl generated rt information about events
0003 %             listed in blf file
0004 %
0005 % Usage:
0006 %  >> rt_vector=import_rts(rtfile,blf_evnum)
0007 %
0008 %
0009 % Global Variable:
0010 %   VERBLEVEL = crw2set level of verbosity (i.e., tells functions
0011 %               how much to report about what they're doing during runtime)
0012 %
0013 %
0014 % Inputs:
0015 %   rtfile     = name of cdbl generated rt file (a string)
0016 %   blf_evnum  = a vector of log item integers for all events that
0017 %                are listed in the corresponding blf file.
0018 %
0019 % Outputs:
0020 %
0021 %   rtmsec   = a cell array with one entry for each blf item. Each cell of the
0022 %               array stores a reaction time (in milliseconds) for each bin
0023 %               that item falls in (this way the same item can have different
0024 %               RTs depending on which bin it's being considered as).
0025 %   rtbins   = a cell array with one entry for each blf item. Each cell of
0026 %               the array indicates which bin the corresponding reaction time
0027 %               in rtmsec belongs to.
0028 %   rtvector = a vector of reaction times (in msec). The nth element
0029 %               of rt_vector corresponds to the nth element of
0030 %               blf_evnum.  If an element of blf_evnum does not have
0031 %               a reaction time listed in rtfile, the corresponding
0032 %               element of rt_vector is NaN.  This can be used to create a
0033 %               field in EEG.epoch (which makes it easier to access RTs via
0034 %               the EEGLAB GUI). However, if a single blf item has more than
0035 %               one RT, you can't use this option and it will be empty.
0036 %
0037 % Author:
0038 % David Groppe
0039 % Kutaslab, 8/2009
0040 
0041 global VERBLEVEL
0042 
0043 mult_rt=0; %flag that indicates if more than one RT is paired with that item
0044 %Grab RTs from specified RT file or from temporarily generated rtfile
0045 rtvector=[];
0046 if ~isempty(rtfile)
0047   VerbReport(sprintf('\nGetting RT information from %s', rtfile), ...
0048          1, VERBLEVEL);  
0049   evnum1=[]; evcode1=[]; flag1=[]; time1ms=[]; evnum2=[]; evcode2=[]; flag2=[]; time2ms=[]; RT=[]; bin=[];
0050   [evnum1, evcode1, flag1, time1ms, evnum2, evcode2, flag2, time2ms, RT,  bin] =  ...
0051       textread(rtfile, '%d %d %d %d %d %d %d %d %d %d', 'headerlines', 1);
0052   if isempty(RT)
0053     VerbReport(sprintf('File %s contains NO RTs. RT import aborted.', rtfile), ...
0054            1, VERBLEVEL);   
0055     rtvector=[];
0056     rtbins=[];
0057     rtmsec=[];
0058   else
0059     %pre-allocate memory
0060     rtvector=zeros(length(blf_evnum),1)*NaN; %default is no RT, which is represented by NaN
0061     uni_bins=unique(bin);
0062     
0063     clear rtmsec rtbins
0064     ct=0;
0065     for itm_id=blf_evnum,
0066       ct=ct+1;
0067       rt_id=find(evnum1==itm_id); 
0068     if isempty(rt_id),
0069         rtbins{ct}=NaN;
0070         rtmsec{ct}=NaN;
0071     else
0072       rt_bins=bin(rt_id);
0073       rtbins{ct}=zeros(1,length(rt_bins));
0074       rtmsec{ct}=zeros(1,length(rt_bins));
0075       bin_ct=0;
0076       for b=rt_bins',
0077           bin_ct=bin_ct+1;
0078           rtbins{ct}(bin_ct)=b;
0079           rtmsec{ct}(bin_ct)=RT(rt_id(bin_ct));
0080       end
0081       uni=unique(RT(rt_id));
0082       if (length(uni)==1) & ~mult_rt,
0083           rtvector(ct)=uni;
0084       else
0085           mult_rt=1;
0086           msg=sprintf(['File %s has multiple different reaction ' ...
0087               'times for log item: %d.'],rtfile,itm_id);
0088           VerbReport(msg,2, VERBLEVEL);
0089       end
0090     end
0091     end
0092   end
0093 end
0094 
0095 if mult_rt,
0096     VerbReport('',1,VERBLEVEL);
0097     msg=sprintf(['File %s has multiple different reaction ' ...
0098         'times for at least one log item.\nThus, rtvector is empty and no rtmsec category' ...
0099         ' will be made in EEG.event.\n'],rtfile);
0100     msg=[msg ' The cell arrays rtmsec and rtbins has RT information and can be used by *MK.m functions.'];
0101     VerbReport(msg,1,VERBLEVEL);
0102     VerbReport('',1,VERBLEVEL);
0103     rtvector=[];
0104 end

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