Home > matlabmk > gui_avgs2GND.m

gui_avgs2GND

PURPOSE ^

avgs2GND() - Create a MATLABmk GND struct variable from a set of

SYNOPSIS ^

function GND=gui_avgs2GND()

DESCRIPTION ^

 avgs2GND() - Create a MATLABmk GND struct variable from a set of
              Kutaslab ERP files (e.g., files that end in *.nrm) and text
              file indicating electrode positions.

 Usage:
  >> GND=avgs2GND(infiles_or_tmplt,varargin);

 Required Inputs:
   infiles_or_tmplt - [cell array of strings or a string] If a cell array
                      of strings, each element of the cell array should 
                      contain the filename of a Kutaslab ERP file (e.g., 
                      {'visodbl01.nrm','visodbl02.nrm'}.  Otherwise, this 
                      input should be filename template (i.e., a string with
                       # where the subject number should be--'visodbl#.nrm').  
                      If you provide a template, you must use the option
                      'sub_ids' (see below) to specify the ID numbers of
                      each subject. Include the files' path unless the files 
                      are in the current working directory.


 Optional Inputs:
   sub_ids          - [integer vector] A set of integers specifying the
                      subject ID numbers to include in the grand average.  
                      Only necessary if a filename template is given as 
                      the input to infiles_or_tmplt.

   locfile          - A text file specifying electrode coordinates according
                      to EEGLAB spherical coordinate conventions. See
                      /usr/local/matlab-toolboxes/matlabmk/demo_files/mk32.loc or
                      /usr/local/matlab-toolboxes/matlabmk/demo_files/mk64.loc  
                      for examples. The order of the channels should match
                      that of the header in the Kutaslab average files
                      (i.e., the order of the channel labels shown when
                      you run headinfo on the average file). If you do NOT
                      specify a locfile, the function will try to assign
                      default electrode coordinates based on standard
                      Kutaslab channel names (e.g., 'MiCe','LLOc','heog').
                      In addition to the standard cap channel names, the
                      following loose lead names are recognized by this
                      function.  Note, channel matching is not case 
                      sensitive (e.g., 'lle' is the same as 'LLE').
                      {default: try to match channel names to standard
                      coordinates}
                       'A2'=Left Mastoid
                       'lle' or 'LLEy'=Left Lower Eye
                       'rle' or 'RLEy'=Right Lower Eye
                       'lhe', 'lhz', or 'LHEy'=Left Horizontal Eye
                       'rhe', 'rhz', or 'RHEy'=Right Horizontal Eye
                       'HE' or 'heog'=Horizontal Eye Montage (e.g., lhe-rhe)
                       'VE' or 'veog'=Vertical Eye Montage (e.g., lle-rle)

   bsln             - [vector] A pair of numbers (in milliseconds)
                      specifying the start and end times of the ERP baseline 
                      window.  The mean voltage in the baseline window will
                      be removed from each ERP. {default: use all time 
                      points before time 0).

   use_bins         - [integer vector] A set of integers specifying which
                      bins to import into MATLAB.  If not specified, all 
                      bins will be imported. Note, if you import only a 
                      subset of bins, the bin numberings will start at 1 
                      and run to the number you've imported (i.e., the may
                      differ from the bin numbers in the average file. 
                      {default: import all bins}

   exclude_chans    - A cell array of channel labels to exclude from the
                      permutation test (e.g., {'A2','lle','rhe'}). You cannot
                      use both this option and 'include_chans' (below).{default:
                      not used, import all channels}

   include_chans    - A cell array of channel labels to use in the permutation
                      test (e.g., {'A2','lle','rhe'}).  All other channels will
                      be ignored. You cannot use both this option and 
                      'exclude_chans' (above). {default: not used, import 
                      all channels}

 Output:
   GND  - Struct variable containing grand averages, individual subject
          ERPs, permutation test results and more.

 Notes:
 -Bin 0 is assumed to be cal pulses and is stored as a separate field
 in GND (it is not stored as a bin).  Consequently, bin indexing starts at 
 1 (not 0 like in the lab).

 Author:
 David Groppe
 Kutaslab, 3/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function GND=gui_avgs2GND()
0002 % avgs2GND() - Create a MATLABmk GND struct variable from a set of
0003 %              Kutaslab ERP files (e.g., files that end in *.nrm) and text
0004 %              file indicating electrode positions.
0005 %
0006 % Usage:
0007 %  >> GND=avgs2GND(infiles_or_tmplt,varargin);
0008 %
0009 % Required Inputs:
0010 %   infiles_or_tmplt - [cell array of strings or a string] If a cell array
0011 %                      of strings, each element of the cell array should
0012 %                      contain the filename of a Kutaslab ERP file (e.g.,
0013 %                      {'visodbl01.nrm','visodbl02.nrm'}.  Otherwise, this
0014 %                      input should be filename template (i.e., a string with
0015 %                       # where the subject number should be--'visodbl#.nrm').
0016 %                      If you provide a template, you must use the option
0017 %                      'sub_ids' (see below) to specify the ID numbers of
0018 %                      each subject. Include the files' path unless the files
0019 %                      are in the current working directory.
0020 %
0021 %
0022 % Optional Inputs:
0023 %   sub_ids          - [integer vector] A set of integers specifying the
0024 %                      subject ID numbers to include in the grand average.
0025 %                      Only necessary if a filename template is given as
0026 %                      the input to infiles_or_tmplt.
0027 %
0028 %   locfile          - A text file specifying electrode coordinates according
0029 %                      to EEGLAB spherical coordinate conventions. See
0030 %                      /usr/local/matlab-toolboxes/matlabmk/demo_files/mk32.loc or
0031 %                      /usr/local/matlab-toolboxes/matlabmk/demo_files/mk64.loc
0032 %                      for examples. The order of the channels should match
0033 %                      that of the header in the Kutaslab average files
0034 %                      (i.e., the order of the channel labels shown when
0035 %                      you run headinfo on the average file). If you do NOT
0036 %                      specify a locfile, the function will try to assign
0037 %                      default electrode coordinates based on standard
0038 %                      Kutaslab channel names (e.g., 'MiCe','LLOc','heog').
0039 %                      In addition to the standard cap channel names, the
0040 %                      following loose lead names are recognized by this
0041 %                      function.  Note, channel matching is not case
0042 %                      sensitive (e.g., 'lle' is the same as 'LLE').
0043 %                      {default: try to match channel names to standard
0044 %                      coordinates}
0045 %                       'A2'=Left Mastoid
0046 %                       'lle' or 'LLEy'=Left Lower Eye
0047 %                       'rle' or 'RLEy'=Right Lower Eye
0048 %                       'lhe', 'lhz', or 'LHEy'=Left Horizontal Eye
0049 %                       'rhe', 'rhz', or 'RHEy'=Right Horizontal Eye
0050 %                       'HE' or 'heog'=Horizontal Eye Montage (e.g., lhe-rhe)
0051 %                       'VE' or 'veog'=Vertical Eye Montage (e.g., lle-rle)
0052 %
0053 %   bsln             - [vector] A pair of numbers (in milliseconds)
0054 %                      specifying the start and end times of the ERP baseline
0055 %                      window.  The mean voltage in the baseline window will
0056 %                      be removed from each ERP. {default: use all time
0057 %                      points before time 0).
0058 %
0059 %   use_bins         - [integer vector] A set of integers specifying which
0060 %                      bins to import into MATLAB.  If not specified, all
0061 %                      bins will be imported. Note, if you import only a
0062 %                      subset of bins, the bin numberings will start at 1
0063 %                      and run to the number you've imported (i.e., the may
0064 %                      differ from the bin numbers in the average file.
0065 %                      {default: import all bins}
0066 %
0067 %   exclude_chans    - A cell array of channel labels to exclude from the
0068 %                      permutation test (e.g., {'A2','lle','rhe'}). You cannot
0069 %                      use both this option and 'include_chans' (below).{default:
0070 %                      not used, import all channels}
0071 %
0072 %   include_chans    - A cell array of channel labels to use in the permutation
0073 %                      test (e.g., {'A2','lle','rhe'}).  All other channels will
0074 %                      be ignored. You cannot use both this option and
0075 %                      'exclude_chans' (above). {default: not used, import
0076 %                      all channels}
0077 %
0078 % Output:
0079 %   GND  - Struct variable containing grand averages, individual subject
0080 %          ERPs, permutation test results and more.
0081 %
0082 % Notes:
0083 % -Bin 0 is assumed to be cal pulses and is stored as a separate field
0084 % in GND (it is not stored as a bin).  Consequently, bin indexing starts at
0085 % 1 (not 0 like in the lab).
0086 %
0087 % Author:
0088 % David Groppe
0089 % Kutaslab, 3/2010
0090 
0091 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0092 %
0093 % 3/9/10 Added 'use_bins' option and code now automatically checks to see
0094 % if it should pad subject ids less than 10 with a 0 in filenames (e.g.,
0095 % odbl02.nrm).  It looks to see if the padded or non-padded files exist, and
0096 % then takes the one that exists. I also got rid of carriage return at end
0097 % of condition descriptors. -DG
0098 %
0099 % 3/9/10 Added 'include_chans' and 'exclude_chans' option. -DG
0100 %
0101 
0102 
0103 %%%%%%%%%%%%%%%% Future Work  %%%%%%%%%%%%%%%%%
0104 %
0105 % Make a GUI for the code (esp for adding files)
0106 %
0107 % ?? If any input files are not found, ask if user wants to continue
0108 % without them? (currently it just aborts)
0109 %
0110 % ?? add more comments about GND output
0111 %
0112 % make it possible to import subject traits (e.g., age, median RT) from
0113 % text file
0114 
0115 % global VERBLEVEL; ?? uncomment once VERBLEVEL is working
0116 
0117 
0118 [infname, inpath]=uigetfile({'*.mas','*.mas files'; ...
0119     '*.cms','*.cms files'; ...
0120     '*.nrm','*.nrm files'; ...
0121     '*.cnm','*.cnm files'; ...
0122     '*.iccor',' *.iccor files'; ...
0123     '*.*','All Files (*.*)'},'First select Kutaslab average files to import','MultiSelect','on');
0124 if ~inpath,
0125     fprintf('File selection cancelled.  Aborting gui_avgs2GND.\n');
0126     GND=[];
0127     return;
0128 else
0129     infiles=cell(1,length(infname));
0130     for a=1:length(infname),
0131         infiles{a}=[inpath infname{a}];
0132     end
0133 end
0134 
0135 
0136 %load first file to get channel labels, time window, and bin information
0137 
0138 %then trigger GUI to allow people to select a subset of channels, subset of
0139 %bins, and baseline time window
0140 
0141 %then run avgs2GND with optional input arguments
0142 
0143 
0144 n_subs=length(infiles);
0145 for sub=1:n_subs,
0146     
0147     %open avg file
0148     fprintf('Opening file %s\n',infiles{sub});
0149     fid=erpio('openavg',infiles{sub});
0150     if (fid==-1)
0151         msg=erpio('get_errstr');
0152         error('Could not open file %s using erpio. According to erpio: %s', ...
0153             infiles{sub},msg);
0154     end
0155     
0156     %% Check Channel Label Compatibility
0157     n_chans=erpio('get_hdrvar',fid,'chans',1);
0158     use_chans=zeros(1,n_chans);
0159     used_chan_ct=0;
0160     % Channel locations from locfile or from initial subject
0161     if ~isempty(p.Results.locfile) || (sub>1), 
0162         for c=1:n_chans,
0163             chan_label=erpio('get_hdrvar',fid,'chndesc',c-1,1); %for chan #c, bin #1
0164             if ismember(chan_label,use_chan_labels),
0165                 used_chan_ct=used_chan_ct+1;
0166                 if ~strcmpi(GND.chanlocs(used_chan_ct).labels,chan_label),
0167                     erpio('close',fid);
0168                     error('In %s, the #%d used channel is %s.  In %s, it is %s.\n', ...
0169                         infiles{sub},used_chan_ct,chan_label,locfile,GND.chanlocs(used_chan_ct).labels);
0170                 else
0171                    use_chans(c)=1; 
0172                 end
0173             end
0174         end
0175         if sum(use_chans)~=n_use_chans,
0176             erpio('close',fid);
0177             error('File %s has a different number of channels than all previous files.', ...
0178                 infiles{sub});
0179         end
0180     else
0181         %Try to create chanlocs from library of locations for initial
0182         %subject
0183         if n_chans>=59,
0184             %Try to match with 59 channel cap "chanlocs" variable
0185             load('/usr/local/matlab-toolboxes/matlabmk/mk66locs');
0186         else
0187             %Try to match with 26 channel cap "chanlocs" variable
0188             load('/usr/local/matlab-toolboxes/matlabmk/mk33locs');
0189         end
0190         n_chanlocs=length(chanlocs);
0191         for c=1:n_chans,
0192             chan_label=erpio('get_hdrvar',fid,'chndesc',c-1,1); %for chan #c, bin #1
0193             use_chans(c)=1;
0194             if ~isempty(exclude_chans) && ismember(chan_label,exclude_chans),
0195                 use_chans(c)=0;
0196             end
0197             if ~isempty(include_chans) && ~ismember(chan_label,include_chans),
0198                 use_chans(c)=0;
0199             end
0200             if use_chans(c),
0201                 used_chan_ct=used_chan_ct+1;
0202                 %Standardize Channel Names
0203                 if strcmpi(chan_label,'lle'),
0204                     avg_label='LLEy';
0205                 elseif strcmpi(chan_label,'rle'),
0206                     avg_label='RLEy';
0207                 elseif strcmpi(chan_label,'lhe') || strcmpi(chan_label,'lhz'),
0208                     avg_label='LHEy';
0209                 elseif strcmpi(chan_label,'rhe') || strcmpi(chan_label,'rhz'),
0210                     avg_label='RHEy';
0211                 elseif strcmpi(chan_label,'HE'),
0212                     avg_label='HEOG';
0213                 elseif strcmpi(chan_label,'VE'),
0214                     avg_label='VEOG';
0215                 else
0216                     avg_label=chan_label;
0217                 end
0218                 found=0;
0219                 for d=1:n_chanlocs,
0220                     if strcmpi(avg_label,chanlocs(d).labels),
0221                         if used_chan_ct==1,
0222                             GND.chanlocs=chanlocs(d); %create new struct
0223                         else
0224                             GND.chanlocs(used_chan_ct)=chanlocs(d);
0225                         end
0226                         GND.chanlocs(used_chan_ct).labels=chan_label;
0227                         found=1;
0228                     end
0229                 end
0230                 if ~found,
0231                     watchit(sprintf(['Could not find a default coordinate for channel %s. ' ...
0232                         'Giving it the bogus coordinate of a few inches in front of the nose.\n'],chan_label));
0233                     GND.chanlocs(used_chan_ct)=chanlocs(n_chanlocs); %the last electrode should be VEOG
0234                     GND.chanlocs(used_chan_ct).labels=chan_label;
0235                 end
0236             end
0237         end
0238         n_use_chans=used_chan_ct;
0239         use_chan_labels=cell(1,n_use_chans);
0240         for d=1:n_use_chans,
0241             use_chan_labels{d}=GND.chanlocs(d).labels;
0242         end
0243     end
0244     
0245     %% Check # of bins
0246     n_bins=erpio('getnbins',fid); %note bin count starts with 0 (i.e. goes from 0 to n_bins-1)
0247     if ~isempty(GND.indiv_erps),
0248         if n_bins~=total_psbl_bins,
0249              erpio('close',fid);
0250              error('File %s has %d bins.  The previous files have %d bins (counting Bin 0, which should contain cal pulses).', ...
0251                  infiles{sub},n_bins,total_psbl_bins);
0252         end
0253     end
0254     if sub==1,
0255         if isempty(p.Results.use_bins),
0256             use_bins=1:(n_bins-1);
0257         else
0258             use_bins=p.Results.use_bins;
0259         end
0260         total_psbl_bins=n_bins;
0261     end
0262     
0263     %% Check Experiment Descriptor
0264     if isempty(GND.exp_desc),
0265         GND.exp_desc=erpio('get_hdrvar',fid,'expdesc',1);
0266     else
0267         neo_desc=erpio('get_hdrvar',fid,'expdesc',1);
0268         if ~strcmpi(GND.exp_desc,neo_desc),
0269             watchit(sprintf('The experiment descriptor for file %s is %s.\nUsing initial descriptor: %s.\n', ...
0270                 infiles{sub},neo_desc,GND.exp_desc));
0271         end
0272     end
0273     
0274     %% Create/Check Bin Descriptor
0275     if isempty(GND.bindesc),
0276         %write bindesc
0277         bin_ct=0;
0278         for b=use_bins,
0279             bin_ct=bin_ct+1;
0280             GND.bindesc{bin_ct}=erpio('get_hdrvar',fid,'bindesc',b);
0281         end
0282         GND.cals.caldesc=erpio('get_hdrvar',fid,'bindesc',0);
0283     else
0284         %check bindesc
0285         bin_ct=0;
0286         for b=use_bins,
0287             bin_ct=bin_ct+1;
0288             neo_bindesc=erpio('get_hdrvar',fid,'bindesc',b);
0289             if ~strcmpi(GND.bindesc{bin_ct},neo_bindesc),
0290                 erpio('close',fid);
0291                 error('The bin descriptor for file %s, Bin %d is %s.  For previous file(s) it is %s.', ...
0292                     infiles{sub},b,neo_bindesc,GND.bindesc{bin_ct});
0293             end
0294         end
0295         %cal pulse bin
0296         neo_bindesc=erpio('get_hdrvar',fid,'bindesc',0);
0297         if ~strcmpi(GND.cals.caldesc,neo_bindesc),
0298             erpio('close',fid);
0299             error('The bin descriptor for file %s, Bin %d is %s.  For previous file(s) it is %s.', ...
0300                 infiles{sub},0,neo_bindesc,GND.cals.caldesc);
0301         end
0302     end
0303   
0304     %% Create/Check Condition Codes
0305     if isempty(GND.condcode),
0306         %write condition codes
0307         bin_ct=0;
0308         for b=use_bins,
0309             bin_ct=bin_ct+1;
0310             GND.condcode(bin_ct)=erpio('get_hdrvar',fid,'condcode',b);
0311         end
0312         GND.cals.condcode=erpio('get_hdrvar',fid,'condcode',0);
0313     else
0314         %check condition codes
0315         bin_ct=0;
0316         for b=use_bins,
0317             bin_ct=bin_ct+1;
0318             neo_ccode=erpio('get_hdrvar',fid,'condcode',b);
0319             if neo_ccode~=GND.condcode(bin_ct),
0320                 erpio('close',fid);
0321                 error('The condition code for Bin %d in file %s is %d.  In previous file(s) it is %d.', ...
0322                     b,infiles{sub},neo_ccode,GND.condcode(bin_ct));
0323             end
0324         end
0325         %cal pulse condition code
0326         neo_ccode=erpio('get_hdrvar',fid,'condcode',0);
0327         if neo_ccode~=GND.cals.condcode,
0328             erpio('close',fid);
0329             error('The condition code for Bin 0 in file %s is %d.  In previous file(s) it is %d.', ...
0330                 infiles{sub},neo_ccode,GND.cals.condcode);
0331         end
0332     end
0333     
0334     %% Check Condition Code Descriptor
0335     if isempty(GND.condesc),
0336         %Create condition code descriptor field
0337         
0338         %cal pulse condition code descriptor
0339         GND.cals.condesc=erpio('get_hdrvar',fid,'condesc',0);
0340         
0341         if sum(use_bins>1),
0342             %write condition code descriptors for ERP bins
0343             n_ccode=1;
0344             GND.condesc{n_ccode}=erpio('get_hdrvar',fid,'condesc',use_bins(1));
0345             if length(use_bins)>1,
0346                 for b=use_bins(2:end),
0347                     neo_ccdesc=erpio('get_hdrvar',fid,'condesc',b);
0348                     if ~strcmpi(neo_ccdesc,GND.condesc{n_ccode}),
0349                         n_ccode=n_ccode+1;
0350                         GND.condesc{n_ccode}=neo_ccdesc;
0351                     end
0352                 end
0353             end
0354         end
0355     else
0356         %Check condition code descriptor field
0357         bin_ct=0;
0358         for b=use_bins,
0359             bin_ct=bin_ct+1;
0360             neo_condesc=erpio('get_hdrvar',fid,'condesc',b);
0361             if ~strcmpi(GND.condesc{GND.condcode(bin_ct)},neo_condesc),
0362                 erpio('close',fid);
0363                 error('The condition code descriptor for file %s, Bin %d is %s.  For previous file(s) it is %s.', ...
0364                     infiles{sub},b,neo_condesc,GND.condesc{GND.condcode(bin_ct)});
0365             end
0366         end
0367         %cal pulse bin
0368         neo_condesc=erpio('get_hdrvar',fid,'condesc',0);
0369         if ~strcmpi(GND.cals.condesc,neo_condesc),
0370             erpio('close',fid);
0371             error('The condition code descriptor for file %s, Bin %d is %s.  For previous file(s) it is %s.', ...
0372                 infiles{sub},0,neo_condesc,GND.cals.condesc);
0373         end
0374     end    
0375     
0376     
0377     %% Check Time Points
0378     cprecis=erpio('get_hdrvar',fid,'cprecis',1);
0379     presamp=erpio('get_hdrvar',fid,'presampling',1);
0380     srate=100000/erpio('get_hdrvar',fid,'clktick',1);
0381     GND.srate=srate;
0382     if isempty(GND.time_pts),
0383         n_pts=cprecis*256;
0384         GND.time_pts=[0:(n_pts-1)]*1000/srate-presamp;
0385         if isempty(p.Results.bsln),
0386            bsln=[-presamp -1000/srate]; %stops right before 0
0387            fprintf('Using default baseline of %d to %d ms ', ...
0388                -presamp,-1000/srate);
0389         else
0390            bsln=p.Results.bsln; 
0391            fprintf('Using baseline of %d to %d ms ', ...
0392                bsln(1),bsln(2));
0393         end
0394         bsln_pts=[find_tpt(bsln(1),GND.time_pts):find_tpt(bsln(2),GND.time_pts)];
0395         fprintf('(%d to %d in time points)\n',bsln_pts(1),bsln_pts(end));
0396     else
0397         cprecis=erpio('get_hdrvar',fid,'cprecis',1);
0398         presamp=erpio('get_hdrvar',fid,'presampling',1);
0399         srate=100000/erpio('get_hdrvar',fid,'clktick',1);
0400         neo_pts=cprecis*256;
0401         if neo_pts~=n_pts,
0402             erpio('close',fid);
0403            error('File %s has %d time points of EEG.  Previous file(s) have %d.', ...
0404                infiles{sub},neo_pts,n_pts);
0405         end
0406         neo_time_pts=[0:(n_pts-1)]*1000/srate-presamp;
0407         if sum(neo_time_pts~=GND.time_pts),
0408             erpio('close',fid);
0409             error('File %s has either a different sampling rate or prestimulus baseline than previous file(s).', ...
0410                 infiles{sub});
0411         end
0412     end
0413 
0414     %% odelay: Currently all avg files are required to have same odelay
0415     if isempty(GND.odelay),
0416         GND.odelay=erpio('get_hdrvar',fid,'odelay',1);
0417     else
0418         odelay=erpio('get_hdrvar',fid,'odelay',1);
0419         if GND.odelay~=odelay,
0420            error('File %s has an odelay of %d. Previous files have an odelay %d.', ...
0421                odelay,GND.odelay);
0422         end
0423     end
0424     
0425     
0426     %% Misc
0427     GND.indiv_fnames{sub}=infiles{sub};
0428     GND.indiv_subnames{sub}=erpio('get_hdrvar',fid,'subdesc',1);
0429 
0430     
0431     %% Initialize ERP variables
0432     n_use_bins=length(use_bins);
0433     if isempty(GND.indiv_erps),
0434         GND.grands=zeros(n_use_chans,n_pts,n_use_bins)*NaN;
0435         GND.grands_stder=GND.grands;
0436         GND.grands_t=GND.grands;
0437         GND.sub_ct=zeros(1,n_use_bins);
0438         GND.indiv_bin_ct=zeros(n_subs,n_use_bins);
0439         GND.indiv_bin_raw_ct=zeros(n_subs,n_use_bins);
0440         GND.indiv_erps=zeros(n_use_chans,n_pts,n_use_bins,n_subs)*NaN;
0441         GND.indiv_art_ics=cell(1,n_subs);
0442         GND.cals.indiv_cals=zeros(n_use_chans,n_pts,n_subs)*NaN;
0443         GND.cals.indiv_cal_ct=zeros(1,n_subs);
0444         GND.cals.grand_cals=zeros(n_use_chans,n_pts)*NaN;
0445     end
0446     
0447 
0448     %% Load ERPs
0449     pp10uv=erpio('get_hdrvar',fid,'pp10uv',1);
0450     bin_ct=0;
0451     for b=use_bins,
0452         bin_ct=bin_ct+1;
0453         GND.indiv_bin_ct(sub,bin_ct)=erpio('get_hdrvar',fid,'sums',b);
0454         GND.indiv_bin_raw_ct(sub,bin_ct)=erpio('get_hdrvar',fid,'totrawrecs',b);
0455         erps=10*erpio('readbin',fid,b)/pp10uv;
0456         erps=rmbase(erps(find(use_chans),:),n_pts,bsln_pts);
0457         GND.indiv_erps(:,:,bin_ct,sub)=erps;
0458     end
0459 
0460     %% Load cal pulses
0461     GND.cals.indiv_cal_ct(sub)=erpio('get_hdrvar',fid,'totrawrecs',0);
0462     erps=10*erpio('readbin',fid,0)/pp10uv;
0463     erps=rmbase(erps(find(use_chans),:),n_pts,bsln_pts);
0464     GND.cals.indiv_cals(:,:,sub)=erps;
0465     
0466     erpio('close',fid);
0467     %cond_code=erpio('get_hdrvar',fid,'condcode',1); %condition code for bin 1
0468     %erpio('get_hdrvar',fid,'condesc',0); %condition descriptor for condition code 0
0469     
0470 end
0471 
0472 
0473 %Average data across participants
0474 for b=1:n_use_bins,
0475     bin_subs=find(GND.indiv_bin_ct(:,b));
0476     GND.sub_ct(b)=length(bin_subs);
0477     if GND.sub_ct(b),
0478         GND.grands(:,:,b)=mean(GND.indiv_erps(:,:,b,bin_subs),4);
0479         GND.grands_stder(:,:,b)=std(GND.indiv_erps(:,:,b,bin_subs),0,4)/sqrt(GND.sub_ct(b));
0480         GND.grands_t(:,:,b)=GND.grands(:,:,b)./GND.grands_stder(:,:,b);
0481     else
0482         watchit(sprintf('No average files contribute to bin %d.',b));
0483     end
0484 end
0485 
0486 %Average cal pulses across participants
0487 GND.cals.grand_cals=mean(GND.cals.indiv_cals,3);
0488 
0489 %get rid of carriage return on bin descriptors
0490 for b=1:n_use_bins,    
0491     if (GND.bindesc{b}(end)==13)
0492         GND.bindesc{b}=GND.bindesc{b}(1:length(GND.bindesc{b})-1);
0493     end
0494 end
0495 
0496 %get rid of carriage return on condition code descriptors
0497 for b=1:length(GND.condesc),    
0498     if (GND.condesc{b}(end)==13)
0499         GND.condesc{b}=GND.condesc{b}(1:length(GND.condesc{b})-1);
0500     end
0501 end
0502 
0503

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