0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 function GND=bin_dif(GND,binA,binB,dif_bindesc,dif_ccode,dif_ccdescr)
0053
0054 if nargin<4,
0055 dif_bindesc=sprintf('Bin %d-Bin %d',binA,binB);
0056 end
0057 if nargin<5,
0058 dif_ccode=[];
0059 end
0060 if nargin<6,
0061 dif_ccdescr=[];
0062 end
0063
0064 GND_copy=GND;
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);
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=dif_bindesc;
0100 ccode1=GND.bin_info(binA).condcode;
0101 ccode2=GND.bin_info(binB).condcode;
0102 if isempty(dif_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=dif_ccode;
0113 if length(GND.condesc)>=dif_ccode,
0114 exist_desc=1;
0115 else
0116 exist_desc=0;
0117 end
0118 if isempty(dif_ccdescr),
0119 if ~exist_desc,
0120 watchit(sprintf('There is no condition code descriptor for Condition Code %d. ', ...
0121 dif_ccode));
0122 GND.condesc{dif_ccode}='Not Specified';
0123 end
0124 else
0125 if exist_desc,
0126 if ~strcmpi(dif_ccdescr,GND.condesc{dif_ccode}),
0127 fprintf('Existing descriptor for Condition Code %d is "%s".\n', ...
0128 dif_ccode,GND.condesc{dif_ccode});
0129 resp=input(sprintf('Do you want me to overwrite existing descriptor with new descriptor of "%s"? (y or n)', ...
0130 dif_ccdescr),'s');
0131 if strcmpi(resp,'y') || strcmpi(resp,'yes'),
0132 GND.condesc{dif_ccode}=dif_ccdescr;
0133 end
0134 end
0135 else
0136 GND.condesc{dif_ccode}=dif_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_dif(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