Home > matlabmk > bin_mean.m

bin_mean

PURPOSE ^

bin_mn() - Computes the difference waves from two bins and stores the

SYNOPSIS ^

function GND=bin_mean(GND,binA,binB,mn_bindesc,mn_ccode,mn_ccdescr)

DESCRIPTION ^

 bin_mn() - Computes the difference waves from two bins and stores the 
             difference as a new bin in a GND variable. The difference
             wave will be binA-binB.
             
 Usage:
  >> GND=bin_mn(GND,binA,binB,mn_bindesc,mn_ccode,mn_ccdescr);

 Required Inputs:
   GND    - A GND structure variable.  To create a GND variable 
            from Kutaslab ERP files (e.g., *.mas files) use avgs2GND.m.  
            To do the same from EEGLAB *.set files use sets2GND.m.
            See Mass Univariate ERP Toolbox documentation for detailed  
            information about the format of a GND variable. 
   binA   - [integer] A bin index. Use the function headinfo.m to see what 
            bins are available.
   binB   - [integer] A bin index. The difference wave will be binA-binB.

 Optional Inputs:
   mn_bindesc - [string] The bin descriptor for the new bin being
                 created. {default: 'Bin #-Bin ##', where # is the value
                 binA and ## is the value of binB}
   mn_ccode   - [integer] The condition code of the new bin being
                 created. Condition codes are specific to Kutaslab data
                 and can be ignored if your lab doesn't support them.
                 {default: condition code of binA}
   mn_ccdescr - [string] The condition code descriptor for the new bin being
                 created. Condition codes are specific to Kutaslab data 
                 and can be ignored if your lab doesn't support them.
                 {default: existing descriptor for that condition code or 
                 'Not Specified'}

 Notes:
 -binA and binB should index bins starting at 1 (i.e., Bin 0 is assumed to
 contain cal pulses and is stored apart from bins in GND variables)

 Example:
 >> GND=bin_mn(GND,2,1,'Targets-Standards'); 

 Author:
 David Groppe
 Kutaslab, 3/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % bin_mn() - Computes the difference waves from two bins and stores the
0002 %             difference as a new bin in a GND variable. The difference
0003 %             wave will be binA-binB.
0004 %
0005 % Usage:
0006 %  >> GND=bin_mn(GND,binA,binB,mn_bindesc,mn_ccode,mn_ccdescr);
0007 %
0008 % Required Inputs:
0009 %   GND    - A GND structure variable.  To create a GND variable
0010 %            from Kutaslab ERP files (e.g., *.mas files) use avgs2GND.m.
0011 %            To do the same from EEGLAB *.set files use sets2GND.m.
0012 %            See Mass Univariate ERP Toolbox documentation for detailed
0013 %            information about the format of a GND variable.
0014 %   binA   - [integer] A bin index. Use the function headinfo.m to see what
0015 %            bins are available.
0016 %   binB   - [integer] A bin index. The difference wave will be binA-binB.
0017 %
0018 % Optional Inputs:
0019 %   mn_bindesc - [string] The bin descriptor for the new bin being
0020 %                 created. {default: 'Bin #-Bin ##', where # is the value
0021 %                 binA and ## is the value of binB}
0022 %   mn_ccode   - [integer] The condition code of the new bin being
0023 %                 created. Condition codes are specific to Kutaslab data
0024 %                 and can be ignored if your lab doesn't support them.
0025 %                 {default: condition code of binA}
0026 %   mn_ccdescr - [string] The condition code descriptor for the new bin being
0027 %                 created. Condition codes are specific to Kutaslab data
0028 %                 and can be ignored if your lab doesn't support them.
0029 %                 {default: existing descriptor for that condition code or
0030 %                 'Not Specified'}
0031 %
0032 % Notes:
0033 % -binA and binB should index bins starting at 1 (i.e., Bin 0 is assumed to
0034 % contain cal pulses and is stored apart from bins in GND variables)
0035 %
0036 % Example:
0037 % >> GND=bin_mn(GND,2,1,'Targets-Standards');
0038 %
0039 % Author:
0040 % David Groppe
0041 % Kutaslab, 3/2010
0042 
0043 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0044 % 3/15/2010-bin_dif command is added to GND variable history
0045 %
0046 % 12/9/2010-Original GND variable returned in case of failure (as opposed
0047 % to NaN)
0048 
0049 %%%%%%%%%%%%%%%% FUTURE WORK %%%%%%%%%%%%%%%%%
0050 % - add verblevel?
0051 
0052 function GND=bin_mean(GND,binA,binB,mn_bindesc,mn_ccode,mn_ccdescr)
0053 
0054 if nargin<4,
0055    mn_bindesc=sprintf('(Bin %d+Bin %d)/2',binA,binB); 
0056 end
0057 if nargin<5,
0058    mn_ccode=[]; 
0059 end
0060 if nargin<6,
0061    mn_ccdescr=[]; 
0062 end
0063 
0064 GND_copy=GND; %copy original variable in case something fails
0065 
0066 [n_chans, n_pts, n_bins, n_subs]=size(GND.indiv_erps);
0067 neo_bin=n_bins+1;
0068 GND.indiv_erps(:,:,neo_bin,:)=zeros(n_chans,n_pts,1,n_subs);
0069 use_subs=[];
0070 for sub=1:n_subs,
0071     if sum(sum(isnan(GND.indiv_erps(:,:,binA,sub))))
0072         fprintf('Sub %d does not have ERPs for Bin %. and will be ignored',sub,binA);
0073         GND.indiv_erps(:,:,neo_bin,sub)=NaN;
0074         GND.indiv_bin_ct(sub,neo_bin)=0;
0075         GND.indiv_bin_raw_ct(sub,neo_bin)=0;
0076     else
0077         if sum(sum(isnan(GND.indiv_erps(:,:,binB,sub))))
0078             fprintf('Sub %d does not have ERPs for Bin %. and will be ignored',sub,binB);
0079             GND.indiv_erps(:,:,neo_bin,sub)=NaN;
0080             GND.indiv_bin_ct(sub,neo_bin)=0;
0081             GND.indiv_bin_raw_ct(sub,neo_bin)=0;
0082         else
0083             GND.indiv_erps(:,:,neo_bin,sub)=(GND.indiv_erps(:,:,binA,sub)+ ...
0084                 GND.indiv_erps(:,:,binB,sub))/2;
0085             GND.indiv_bin_ct(sub,neo_bin)=-1;
0086             GND.indiv_bin_raw_ct(sub,neo_bin)=-1;
0087             use_subs=[use_subs sub];
0088         end
0089     end
0090 end
0091 if isempty(use_subs),
0092     GND=GND_copy;
0093     error('No subjects have ERPs in both Bin %d and Bin %d.  No changes were made to GND variable.\n',binA,binB);
0094 else
0095     GND.sub_ct(neo_bin)=length(use_subs);
0096     GND.grands(:,:,neo_bin)=mean(GND.indiv_erps(:,:,neo_bin,use_subs),4);
0097     GND.grands_stder(:,:,neo_bin)=std(GND.indiv_erps(:,:,neo_bin,use_subs),0,4)/sqrt(GND.sub_ct(neo_bin));
0098     GND.grands_t(:,:,neo_bin)=GND.grands(:,:,neo_bin)./GND.grands_stder(:,:,neo_bin);
0099     GND.bin_info(neo_bin).bindesc=mn_bindesc;
0100     ccode1=GND.bin_info(binA).condcode;
0101     ccode2=GND.bin_info(binB).condcode;
0102     if isempty(mn_ccode)
0103         if ccode1==ccode2,
0104             GND.bin_info(neo_bin).condcode=ccode1;
0105         else
0106             watchit(sprintf(['Bin %d and %d belong to different condition codes. ', ...
0107                 'Condition code for new bin not specified.  Using Condition Code of %d by default.\n'], ...
0108                 binA,binB,ccode1));
0109             GND.bin_info(neo_bin).condcode=ccode1;
0110         end
0111     else
0112         GND.bin_info(neo_bin).condcode=mn_ccode;
0113         if length(GND.condesc)>=mn_ccode,
0114             exist_desc=1;
0115         else
0116             exist_desc=0;
0117         end
0118         if isempty(mn_ccdescr),
0119             if ~exist_desc,
0120                watchit(sprintf('There is no condition code descriptor for Condition Code %d.  ', ... 
0121                    mn_ccode));
0122                GND.condesc{mn_ccode}='Not Specified';
0123             end
0124         else
0125             if exist_desc,
0126                 if ~strcmpi(mn_ccdescr,GND.condesc{mn_ccode}),
0127                     fprintf('Existing descriptor for Condition Code %d is "%s".\n', ...
0128                         mn_ccode,GND.condesc{mn_ccode});
0129                     resp=input(sprintf('Do you want me to overwrite existing descriptor with new descriptor of "%s"? (y or n)', ...
0130                         mn_ccdescr),'s');
0131                     if strcmpi(resp,'y') || strcmpi(resp,'yes'),
0132                         GND.condesc{mn_ccode}=mn_ccdescr;
0133                     end
0134                 end
0135             else
0136                 GND.condesc{mn_ccode}=mn_ccdescr;
0137             end
0138         end
0139     end
0140 end
0141 
0142 fprintf('<<New bin successfully created>>\n');
0143 cc=GND.bin_info(neo_bin).condcode;
0144 fprintf('Condition Code %d: %s\n',cc,GND.condesc{cc});
0145 fprintf('Bin %d: %s\n',neo_bin,GND.bin_info(neo_bin).bindesc);
0146 hist_cmd=sprintf('GND=bin_mn(GND,%d,%d,''%s'',%d,''%s'');',binA,binB, ...
0147     GND.bin_info(neo_bin).bindesc,cc,GND.condesc{cc});
0148 GND.history{length(GND.history)+1}=hist_cmd;
0149 GND.saved='no';
0150

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