Home > matlabmk > specGNDs2specGRP.m

specGNDs2specGRP

PURPOSE ^

specGNDs2specGRP() - Creates a MATLABmk specGRP variable from a set of

SYNOPSIS ^

function specGRP=specGNDs2specGRP(gui_infiles_or_tmplt,varargin)

DESCRIPTION ^

 specGNDs2specGRP() - Creates a MATLABmk specGRP variable from a set of 
              MATLABmk specGND variables.  A specGRP variable is useful
              for doing between-subjects analyses.  Note, all the specGND
              files need to have samples at the same points in time, the
              same baseline window, and compatible sets of electrodes.
              
             
 Usage:
  >> specGRP=specGNDs2specGRP(gui_infiles_or_tmplt,varargin);

 Required Inputs:
   gui_infiles_or_tmplt - ['gui', a cell array of strings, or a string template]
                          If 'gui', a GUI is created that allows you to select
                          which average files to import (this is probably the
                          easiest way to import files).  If a cell array of 
                          of strings, each element of the cell array should 
                          contain the filename of a specGND file (e.g., 
                          {'visodbl_young.specGND','visodbl_old.specGND'}.  Otherwise, this 
                          input should be a filename template (i.e., a string with
                          a # where an ID number should be--'visodbl#.specGND').  
                          If you provide a template, you must use the option
                          'specGND_ids' (see below) to specify the ID numbers of
                          each specGND file. Include the files' path unless the files 
                          are in the current working directory.

 Optional Inputs:
   group_desc       - [cell array] A string for each specGND file that
                      describes that group of participants (e.g., {'young',
                      'old'}).  It might save you typing later to keep 
                      these names simple.  If this option isn't used, a 
                      pop-up window will be created for each specGND file 
                      to request a name for that group. {default: not used}

   exp_desc         - [string] A string that described the experiment. If
                      not specified, the experiment descriptor from the 
                      first specGND file is used. {default: not specified}

   specGND_ids      - [integer vector] A set of integers specifying the
                      specGND file ID numbers of each group of participants.  
                      Only necessary if a filename template is given as 
                      the input to gui_infiles_or_tmplt. {default: not
                      used}

   create_difs      - ['yes' or 'no'] If 'yes', difference waves will be
                      created for each bin in the specGND files between all 
                      possible pairs of groups and added as new bins to 
                      the specGRP variable. The specGND files must all have 
                      the exact same bins (including bin descriptors) to use 
                      this option. {default: not used}

   use_bins         - [integer vector] A set of integers specifying which
                      bins to take difference waves.  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
                      importing (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 the labels of the channels you wish
                      to import (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}

   out_fname        - [string] Filename to save specGND variable to.  If 
                      empty (i.e., not specified), a GUI will be created
                      to prompt you for a filename. If the string 
                      'no save', the specGND variable will not be saved to
                      disk. 

 Output:
   specGRP  - Struct variable containing grand averages derived from pairs of 
              specGND variables, the file names of locations of the source
              specGND files, t-test results and more.

 Example:
   See documentation on between-participant analyses:
     http://kutaslab.pbworks.com/w/page/34101019/Between_Subject_Power_Spectra_Analysis

 Notes:
 -Individual participant power spectra are not stored with the specGRP 
 variable. Rather, whenever they are needed by MATLAB, the source specGND 
 variables are temporarily reloaded.  Thus, it is critical for operations 
 like the creation of new bins, that the source specGND variable files 
 keep the same file name and location as when the specGRP was first created.

 Author:
 David Groppe
 Kutaslab, 12/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % specGNDs2specGRP() - Creates a MATLABmk specGRP variable from a set of
0002 %              MATLABmk specGND variables.  A specGRP variable is useful
0003 %              for doing between-subjects analyses.  Note, all the specGND
0004 %              files need to have samples at the same points in time, the
0005 %              same baseline window, and compatible sets of electrodes.
0006 %
0007 %
0008 % Usage:
0009 %  >> specGRP=specGNDs2specGRP(gui_infiles_or_tmplt,varargin);
0010 %
0011 % Required Inputs:
0012 %   gui_infiles_or_tmplt - ['gui', a cell array of strings, or a string template]
0013 %                          If 'gui', a GUI is created that allows you to select
0014 %                          which average files to import (this is probably the
0015 %                          easiest way to import files).  If a cell array of
0016 %                          of strings, each element of the cell array should
0017 %                          contain the filename of a specGND file (e.g.,
0018 %                          {'visodbl_young.specGND','visodbl_old.specGND'}.  Otherwise, this
0019 %                          input should be a filename template (i.e., a string with
0020 %                          a # where an ID number should be--'visodbl#.specGND').
0021 %                          If you provide a template, you must use the option
0022 %                          'specGND_ids' (see below) to specify the ID numbers of
0023 %                          each specGND file. Include the files' path unless the files
0024 %                          are in the current working directory.
0025 %
0026 % Optional Inputs:
0027 %   group_desc       - [cell array] A string for each specGND file that
0028 %                      describes that group of participants (e.g., {'young',
0029 %                      'old'}).  It might save you typing later to keep
0030 %                      these names simple.  If this option isn't used, a
0031 %                      pop-up window will be created for each specGND file
0032 %                      to request a name for that group. {default: not used}
0033 %
0034 %   exp_desc         - [string] A string that described the experiment. If
0035 %                      not specified, the experiment descriptor from the
0036 %                      first specGND file is used. {default: not specified}
0037 %
0038 %   specGND_ids      - [integer vector] A set of integers specifying the
0039 %                      specGND file ID numbers of each group of participants.
0040 %                      Only necessary if a filename template is given as
0041 %                      the input to gui_infiles_or_tmplt. {default: not
0042 %                      used}
0043 %
0044 %   create_difs      - ['yes' or 'no'] If 'yes', difference waves will be
0045 %                      created for each bin in the specGND files between all
0046 %                      possible pairs of groups and added as new bins to
0047 %                      the specGRP variable. The specGND files must all have
0048 %                      the exact same bins (including bin descriptors) to use
0049 %                      this option. {default: not used}
0050 %
0051 %   use_bins         - [integer vector] A set of integers specifying which
0052 %                      bins to take difference waves.  If not specified, all
0053 %                      bins will be imported. Note, if you import only a
0054 %                      subset of bins, the bin numberings will start at 1
0055 %                      and run to the number you've imported (i.e., the may
0056 %                      differ from the bin numbers in the average file.
0057 %                      {default: import all bins}
0058 %
0059 %   exclude_chans    - A cell array of channel labels to exclude from
0060 %                      importing (e.g., {'A2','lle','rhe'}). You cannot
0061 %                      use both this option and 'include_chans' (below).
0062 %                      {default: not used, import all channels}
0063 %
0064 %   include_chans    - A cell array of the labels of the channels you wish
0065 %                      to import (e.g., {'A2','lle','rhe'}).  All other
0066 %                      channels will be ignored. You cannot use both this
0067 %                      option and 'exclude_chans' (above). {default: not
0068 %                      used, import all channels}
0069 %
0070 %   out_fname        - [string] Filename to save specGND variable to.  If
0071 %                      empty (i.e., not specified), a GUI will be created
0072 %                      to prompt you for a filename. If the string
0073 %                      'no save', the specGND variable will not be saved to
0074 %                      disk.
0075 %
0076 % Output:
0077 %   specGRP  - Struct variable containing grand averages derived from pairs of
0078 %              specGND variables, the file names of locations of the source
0079 %              specGND files, t-test results and more.
0080 %
0081 % Example:
0082 %   See documentation on between-participant analyses:
0083 %     http://kutaslab.pbworks.com/w/page/34101019/Between_Subject_Power_Spectra_Analysis
0084 %
0085 % Notes:
0086 % -Individual participant power spectra are not stored with the specGRP
0087 % variable. Rather, whenever they are needed by MATLAB, the source specGND
0088 % variables are temporarily reloaded.  Thus, it is critical for operations
0089 % like the creation of new bins, that the source specGND variable files
0090 % keep the same file name and location as when the specGRP was first created.
0091 %
0092 % Author:
0093 % David Groppe
0094 % Kutaslab, 12/2010
0095 
0096 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0097 % 5/1/2011: Pre-allocated size of cal pulse ERPs is taken from cal pulse
0098 % ERPs stored in EEG variable as opposed to size of EEG epochs (i.e.
0099 % size(EEG.data))
0100 %
0101 % 5/2/2011: specGRP.n_tapers and specGRP.half_bandwidth fields updated/added.
0102 %
0103 
0104 %%%%%%%%%%%%%%%% FUTURE WORK %%%%%%%%%%%%%%%%%
0105 % -Add Verblevel optional input?
0106 % -Would it be useful to add the field specGRP.sub_ct?
0107 % -Is it really useful to have cal pulse information in a specGRP variable?
0108 % -Would it be useful to have the field specGRP.indiv_bin_pow_dB?
0109 
0110 function specGRP=specGNDs2specGRP(gui_infiles_or_tmplt,varargin)
0111 
0112 p=inputParser;
0113 p.addRequired('gui_infiles_or_tmplt',@(x) ischar(x) || iscell(x));
0114 p.addParamValue('specGND_ids',[],@isnumeric);
0115 p.addParamValue('use_bins',[],@isnumeric);
0116 p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x)); 
0117 p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x));
0118 p.addParamValue('out_fname',[],@ischar);
0119 p.addParamValue('exp_desc',[],@ischar);
0120 p.addParamValue('group_desc',[],@iscell);
0121 p.addParamValue('create_difs','no',@(x) ischar(x) && (strcmpi(x,'no') || strcmpi(x,'yes')) );
0122 p.parse(gui_infiles_or_tmplt,varargin{:});
0123 
0124 
0125 %Figure out which channels to ignore if any
0126 %But first make sure exclude & include options were not both used.
0127 if ~isempty(p.Results.include_chans) && ~isempty(p.Results.exclude_chans)
0128     error('You cannot use BOTH ''include_chans'' and ''exclude_chans'' options.');
0129 end
0130 if ischar(p.Results.exclude_chans),
0131     exclude_chans{1}=p.Results.exclude_chans;
0132 elseif isempty(p.Results.exclude_chans)
0133     exclude_chans=[];
0134 else
0135     exclude_chans=p.Results.exclude_chans;
0136 end
0137 if ischar(p.Results.include_chans),
0138     include_chans{1}=p.Results.include_chans;
0139 elseif isempty(p.Results.include_chans)
0140     include_chans=[];
0141 else
0142     include_chans=p.Results.include_chans;
0143 end
0144 
0145 %Initialize specGRP
0146 specGRP.exp_desc=p.Results.exp_desc;
0147 specGRP.filename=[];
0148 specGRP.filepath=[];
0149 specGRP.saved='no';
0150 specGRP.freqs=[];
0151 specGRP.group_desc=[];
0152 specGRP.specGND_fnames=[];
0153 specGRP.grands_pow_dB=[];   % <-grand average ERPs (chan x time point x  bin)
0154 specGRP.grands_pow_dB_stder=[]; % <-standard error of grand average ERPs (chan x time point x  bin)
0155 specGRP.grands_pow_dB_t=[]; %<-grand average ERPs as t-scores (chan x time point x  bin)
0156 specGRP.dif=[];
0157 specGRP.chanlocs=[];
0158 specGRP.bin_info=[]; %<-stores information about how difference waves were derived (which groups and bins)
0159 specGRP.srate=[];
0160 specGRP.time_pts=[];
0161 specGRP.n_tapers=[];
0162 specGRP.half_bandwidth=[];
0163 specGRP.indiv_fnames=[];
0164 specGRP.indiv_subnames=[];
0165 specGRP.indiv_traits=[];
0166 specGRP.indiv_bin_ct=[];
0167 specGRP.indiv_bin_raw_ct=[];
0168 specGRP.indiv_art_ics=[];
0169 specGRP.cals.indiv_cals=[]; 
0170 specGRP.cals.indiv_cal_ct=[];
0171 specGRP.cals.grand_cals=[]; %useful? ??
0172 specGRP.history=[];
0173 specGRP.t_tests=[];
0174 
0175 
0176 if strcmpi(gui_infiles_or_tmplt,'GUI'),
0177     loading=1;
0178     infiles=[];
0179     while loading,
0180         fprintf('Select specGND files to import.\n');
0181         fprintf('To select multiple contiguous files in the same directory, hold down the shift key when selecting.\n');
0182         fprintf('To select files in multiple directories or non-contiguous files in the same direcotry,\n');
0183         fprintf('select all the files in one directory and hit the "Open" button.\n');
0184         fprintf('You will then be given the opportunity to load more files from the current or another directory.\n');
0185         [neofname, inpath]=uigetfile({'*.specGND','*.specGND files'; ...
0186             '*.*','All Files (*.*)'},'MATLABmk specGND Files to Import','MultiSelect','on');
0187         if ischar(neofname),
0188             clear infname;
0189             infname{1}=neofname; %make it a cell array for consistent syntax below
0190         else
0191             infname=neofname;
0192         end
0193         if ~inpath,
0194             if isempty(infiles),
0195                 fprintf('File selection cancelled.  Aborting specGNDs2specGRP.\n');
0196                 specGRP=[];
0197                 return;
0198             else
0199                 loading=0;
0200             end
0201         else
0202             if isempty(infiles),
0203                 infiles=cell(1,length(infname)); %preallocate mem
0204                 for a=1:length(infname),
0205                     infiles{a}=[inpath infname{a}];
0206                 end
0207             else
0208                 n_files=length(infiles);
0209                 ct=0;
0210                 for a=(n_files+1):(n_files+length(infname)),
0211                     ct=ct+1;
0212                     infiles{a}=[inpath infname{ct}];
0213                 end
0214             end
0215             % trigger GUI to see if user wants to load more
0216             resp=questdlg('Do you want to load more files?',...
0217                 'OUTPUT','Yes','No','Yes');
0218             if strcmpi(resp,'No'),
0219                 loading=0;
0220             end
0221         end
0222     end
0223 elseif iscell(p.Results.gui_infiles_or_tmplt)
0224     infiles=p.Results.gui_infiles_or_tmplt;
0225 else
0226     if isempty(p.Results.specGND_ids)
0227         error('If gui_infiles_or_tmplt is a string filename template, you must specify the specGND file numbers with the argument ''specGND_ids''.');
0228     elseif ~ismember('#',p.Results.gui_infiles_or_tmplt),
0229         error('The filename template %s needs to contain a # to indicate where the specGND file numbers go (e.g., yngvob#.specGND).', ...
0230             p.Results.gui_infiles_or_tmplt);
0231     else
0232         lb_id=find(p.Results.gui_infiles_or_tmplt=='#');
0233         prefix=p.Results.gui_infiles_or_tmplt(1:(lb_id(1)-1)); %indexing lb_id by 1 in case there are multiple pound signs
0234         postfix=p.Results.gui_infiles_or_tmplt((lb_id(1)+1):end);
0235         n_subs=length(p.Results.specGND_ids);
0236         infiles=cell(1,n_subs);
0237         for s=1:n_subs,
0238             no_pad=[prefix num2str(p.Results.specGND_ids(s)) postfix];
0239             if p.Results.specGND_ids(s)<10,
0240                 padded=[prefix num2str(p.Results.specGND_ids(s),'%.2d') postfix];
0241                 [sP wP]=unix(['ls ' padded]); %if sp==0, then the file exists, need wP argument so that it isn't automatically displayed in command window
0242                 [sNP wNP]=unix(['ls ' no_pad]);
0243                 if ~sP
0244                     if ~sNP,
0245                         error('You have a file named %s and one named %s.  I don''t know which one to load!\n', ...
0246                             padded,no_pad);
0247                     else
0248                         infiles{s}=padded;
0249                     end
0250                 else
0251                     infiles{s}=no_pad;
0252                 end
0253             else
0254                 infiles{s}=no_pad;
0255             end
0256         end
0257     end
0258 end
0259 
0260 % Add group descriptors if specified
0261 if ~isempty(p.Results.group_desc),
0262     if length(p.Results.group_desc)~=length(infiles),
0263         error('The number of group descriptors needs to equal the number of specGND files.');
0264     else
0265         specGRP.group_desc=p.Results.group_desc;
0266     end
0267 end
0268 
0269 if strcmpi(p.Results.create_difs,'yes'),
0270     create_difs=1;
0271 else
0272     create_difs=0;
0273 end
0274 
0275 specGRP.specGND_fnames=infiles;
0276 n_groups=length(infiles);
0277 if n_groups<2,
0278    error('You need at least two specGND files to make a specGRP variable.'); 
0279 end
0280 
0281 for grp=1:n_groups,
0282     
0283     %load new specGND variable
0284     specGND=[];
0285     load(infiles{grp},'-MAT');
0286     if isempty(specGND),
0287        error('File %s needs to contain a MATLABmk specGND variable that is called "specGND"',infiles{grp}); 
0288     end
0289        
0290     if isempty(p.Results.group_desc),
0291        resp=inputdlg(sprintf('Enter the group descriptor for the participants in file %s (e.g., patients).', ...
0292            infiles{grp}),'Name Group of Participants');
0293        specGRP.group_desc{grp}=resp{1};
0294     end
0295     
0296     %Set group general fields/check for specGND field compatibility
0297     if grp==1,
0298         %set group general fields
0299         [n_chans, n_freqs, n_bins, n_subs1]=size(specGND.indiv_pow_dB);
0300         
0301         if create_difs,
0302             % select bins (in case only a subset were requested)
0303             if isempty(p.Results.use_bins),
0304                 use_bins=1:n_bins;
0305             else
0306                 use_bins=p.Results.use_bins;
0307             end
0308             n_use_bins=length(use_bins);
0309         end
0310             
0311         if isempty(specGRP.exp_desc),
0312             specGRP.exp_desc=specGND.exp_desc;
0313         end        
0314         
0315         % select channels (in case only a subset were requested)
0316         if ~isempty(exclude_chans),
0317             use_chans=ones(1,n_chans); %preallocate mem
0318             for c=1:n_chans,
0319                 for a=1:length(exclude_chans)
0320                     if strcmpi(specGND.chanlocs(c).labels,exclude_chans{a}),
0321                         use_chans(c)=0;
0322                         break;
0323                     end
0324                 end
0325             end
0326             use_chans=find(use_chans>0);
0327         elseif ~isempty(include_chans),
0328             use_chans=zeros(1,n_chans); %preallocate mem
0329             for c=1:n_chans,
0330                 for a=1:length(include_chans)
0331                     if strcmpi(specGND.chanlocs(c).labels,include_chans{a}),
0332                         use_chans(c)=1;
0333                         break;
0334                     end
0335                 end
0336             end
0337             use_chans=find(use_chans>0);
0338         else
0339             use_chans=1:n_chans;
0340         end
0341         specGRP.chanlocs=specGND.chanlocs(use_chans);
0342         specGRP.freqs=specGND.freqs;
0343         specGRP.time_pts=specGND.time_pts;
0344         specGRP.n_tapers=specGND.n_tapers;
0345         specGRP.half_bandwidth=specGND.half_bandwidth;
0346         specGRP.srate=specGND.srate;
0347         if isempty(specGND.cals),
0348             specGRP.cals=[];
0349         else
0350             n_cal_tpts=size(specGND.cals.indiv_cals,2);
0351             specGRP.cals.grand_cals=zeros(length(use_chans),n_cal_tpts,n_groups);
0352             specGRP.cals.caldesc=specGND.cals.caldesc;
0353         end
0354         
0355         if create_difs,
0356             %preallocate mem
0357             bin_sub_ct=zeros(n_use_bins,n_groups);
0358             bindesc=cell(1,n_use_bins);
0359             bin_ct=0;
0360             for b=use_bins,
0361                 bin_ct=bin_ct+1;
0362                 bindesc{bin_ct}=specGND.bindesc{b};
0363             end
0364         end
0365     else
0366         %check for compatibility with previously loaded specGND variables
0367         [n_chansNEO, n_freqsNEO, n_binsNEO, n_subsNEO]=size(specGND.indiv_pow_dB);
0368                 
0369         % select channels (in case only a subset were requested)
0370         if ~isempty(exclude_chans),
0371             use_chans=ones(1,n_chansNEO); %preallocate mem
0372             for c=1:n_chansNEO,
0373                 for a=1:length(exclude_chans),
0374                     if strcmpi(specGND.chanlocs(c).labels,exclude_chans{a}),
0375                         use_chans(c)=0;
0376                         break;
0377                     end
0378                 end
0379             end
0380             use_chans=find(use_chans>0);
0381         elseif ~isempty(include_chans),
0382             use_chans=zeros(1,n_chansNEO); %preallocate mem
0383             for c=1:n_chansNEO,
0384                 for a=1:length(include_chans)
0385                     if strcmpi(specGND.chanlocs(c).labels,include_chans{a}),
0386                         use_chans(c)=1;
0387                         break;
0388                     end
0389                 end
0390             end
0391             use_chans=find(use_chans>0);
0392         else
0393             use_chans=1:n_chansNEO;
0394         end
0395         
0396         %Make sure new specGND variable in consistent with the old
0397         if ~isequal(specGND.chanlocs(use_chans),specGRP.chanlocs),
0398             error('The channel location information in the specGND variable from file %s differs from that in previous files.', ...
0399                 infiles{grp});
0400         end
0401         
0402         if ~isequal(specGND.freqs,specGRP.freqs),
0403             error('The frequencies in the specGND variable from file %s differ from those in previous files.', ...
0404                 infiles{grp});
0405         end
0406         
0407         if ~isequal(specGND.time_pts,specGRP.time_pts),
0408             error('The time points in the specGND variable from file %s differ from those in previous files.', ...
0409                 infiles{grp});
0410         end
0411         
0412         if ~isequal(specGND.srate,specGRP.srate),
0413             error('The sampling rate in the specGND variable from file %s differs from that in previous files.', ...
0414                 infiles{grp});
0415         end
0416         
0417         if ~isequal(specGND.n_tapers,specGRP.n_tapers),
0418             error('The number of tapers in the specGND variable from file %s differs from that in previous files.', ...
0419                 infiles{grp});
0420         end
0421      
0422         if ~isequal(specGND.half_bandwidth,specGRP.half_bandwidth),
0423             error('The half frequency bandwidth in the specGND variable from file %s differs from that in previous files.', ...
0424                 infiles{grp});
0425         end
0426         
0427         if ~isempty(specGND.cals) && ~strcmpi(specGND.cals.caldesc,specGRP.cals.caldesc)
0428             watchit(sprintf('The cal pulse bin descriptor in the specGND variable from file %s differs from that in previous files.', ...
0429                 infiles{grp}));
0430         end
0431                
0432         if create_difs,
0433             bin_ct=0;
0434             for b=use_bins,
0435                 bin_ct=bin_ct+1;
0436                 if ~strcmpi(bindesc{bin_ct},specGND.bindesc{b}),
0437                     watchit('Bin descriptor for Bin %d in file %s, differs from that in previous file(s).', ...
0438                         b,infiles{grp});
0439                     fprintf('Bin descriptor for Bin %d, file %s is %s.\n',b,infiles{grp},specGND.bindesc{b})
0440                     fprintf('Bin descriptor for Bin %d, previous file(s) is %s. Using bin descriptor from previous file(s).\n',b,bindesc{bin_ct});
0441                 end
0442             end
0443         end
0444     end
0445     specGRP.indiv_fnames{grp}=specGND.indiv_fnames;
0446     specGRP.indiv_subnames{grp}=specGND.indiv_subnames;
0447     specGRP.indiv_traits{grp}=specGND.indiv_traits;
0448     specGRP.indiv_art_ics{grp}=specGND.indiv_art_ics;
0449     if ~isempty(specGND.cals),
0450         specGRP.cals.indiv_cals{grp}=specGND.cals.indiv_cals(use_chans,:,:);
0451         specGRP.cals.indiv_cal_ct{grp}=specGND.cals.indiv_cal_ct;
0452         specGRP.cals.grand_cals(:,:,grp)=specGND.cals.grand_cals(use_chans,:);
0453     end
0454     
0455     if create_difs,
0456         bin_sub_ct(:,grp)=specGND.sub_ct(use_bins);
0457         specGRP.indiv_bin_ct{grp}=specGND.indiv_bin_ct(:,use_bins);
0458         specGRP.indiv_bin_raw_ct{grp}=specGND.indiv_bin_raw_ct(:,use_bins);
0459         % Grab power spectra from whole group and compute sum of squares
0460         % (SS) for each bin
0461         group_grands(:,:,:,grp)=specGND.grands_pow_dB(use_chans,:,use_bins);
0462         n_subs=zeros(1,1,n_use_bins);
0463         n_subs(1,1,:)=specGND.sub_ct(use_bins);
0464         n_subs=repmat(n_subs,[length(use_chans) n_freqs 1]);
0465         group_ss(:,:,:,grp)=(specGND.grands_pow_dB_stder(use_chans,:,use_bins).^2).*n_subs.*(n_subs-1);
0466     end
0467 end
0468 
0469 if create_difs,
0470     % Compute grand average difference waves & t-scores
0471     dif_ct=0;
0472     for grpA=1:n_groups,
0473         for grpB=(grpA+1):n_groups,
0474             for b=1:n_use_bins,
0475                 dif_ct=dif_ct+1;
0476                 nA=bin_sub_ct(b,grpA); % # of participants who contributed to this bin from Group A
0477                 nB=bin_sub_ct(b,grpB); % # of participants who contributed to this bin from Group B
0478                 specGRP.grands_pow_dB(:,:,dif_ct)=group_grands(:,:,b,grpA)-group_grands(:,:,b,grpB);
0479                 SS_pooled=(group_ss(:,:,b,grpA)+group_ss(:,:,b,grpB))/(nA+nB-2);
0480                 specGRP.grands_pow_dB_stder(:,:,dif_ct)=sqrt( SS_pooled*(nA+nB)/(nA*nB) );
0481                 specGRP.dif(dif_ct)=1;
0482                 % describe difference in bin info
0483                 specGRP.bin_info(b).bindesc=sprintf('%s (%s-%s)',bindesc{b}, ...
0484                     specGRP.group_desc{grpA},specGRP.group_desc{grpB});
0485                 specGRP.bin_info(b).groupA=grpA;
0486                 specGRP.bin_info(b).groupB=grpB;
0487                 specGRP.bin_info(b).source_binA=b;
0488                 specGRP.bin_info(b).source_binB=b;
0489                 specGRP.bin_info(b).n_subsA=nA;
0490                 specGRP.bin_info(b).n_subsB=nB;
0491                 specGRP.bin_info(b).op='A-B';
0492             end
0493         end
0494     end
0495     specGRP.grands_pow_dB_t=specGRP.grands_pow_dB./specGRP.grands_pow_dB_stder;
0496 end
0497 
0498 if isempty(p.Results.out_fname),
0499     %Create GUI
0500     [jname, jpath]=uiputfile({'*.specGRP','*.specGRP files'; ...
0501         '*.*','All files'},'Save specGRP variable as:','untitled.specGRP');
0502     if ~jpath,
0503         fprintf('Output filename selection cancelled.  specGRP variable NOT saved to disk.\n');
0504     else
0505         specGRP=save_matmk(specGRP,jname,jpath,1); % 1 means that user won't be asked again about saving file
0506     end 
0507 elseif ~strcmpi(p.Results.out_fname,'no save'),
0508     [jpath, jname]=pathNname(p.Results.out_fname);
0509     specGRP=save_matmk(specGRP,jname,jpath);
0510 end

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