Home > matlabmk > ic_prop.m

ic_prop

PURPOSE ^

ic_prop() - Plots three basic properties of an independent component

SYNOPSIS ^

function ic_prop(ic_num,varargin)

DESCRIPTION ^

 ic_prop() - Plots three basic properties of an independent component
             (topography, ERPimage, spectra) in a GUI that allows the
             user to change its label (e.g., label it as a particular
             type of artifact)
              
 Usage:
  >> ic_prop(ic_num,varargin)

 Required Input:
   ic_num  - [integer | vector of integers] Number(s) of independent 
             component(s) to plot. 1 is the first IC.  The number of the last 
             IC is the number of columns of EEG.icawinv (typically the
             same as the number of electrodes). If multiple IC numbers are
             specified, the properties of each IC will plot in a separate window.       
             

 Optional Inputs:
   'fig_id'    - [integer | vector of integers] ID number(s) of Matlab 
                 figure windows in which to plot the properties. If ID is 
                 not specified, a new figure window will be generated. If
                 ic_num is a vector of integers, fig_id can be a vector of 
                 of integers of equal length.  If this is done, the first
                 IC specified by ic_num will be plot in the first window 
                 specified by fig_id, etc... {default: []}
   'sortby'    - A string specifying how trials should be sorted when
                 producing the ERPimage.
                  Options are:
                   'logtime' - The time at which the event ocurred
                       (according to the data's log file).  Earliest event 
                       is drawn at the bottom of the ERPimage. {default}
                   'logflag' - The artifact code assigned to the trial by
                        an .arf file. 0=clean trial. 40=nonblink artifact. 
                        60=blink artifact.  Clean trials are drawn at the 
                        bottom of the ERPimage.  Horizontal lines are
                        drawn to separate trial types.  Useful for making
                        sure trials have been accurately garved.
   'from_set_ic_ftr_thresh' - [1 | 0] If 1, ic_prop has been called by the
                              GUI produced by reject_ics_by_ftr.m and will 
                              update the GUI if changes are made to IC labels.
                              If 0, no such update is attempted. {default:
                              0}
   'verblevel' - An integer specifiying the amount of information you want 
                 functions to provide about what they are doing during runtime.
                  Options are:
                    0 - quiet, only show errors, warnings, and EEGLAB reports
                    1 - stuff anyone should probably know
                    2 - stuff you should know the first time you start working
                        with a data set {default value if not already globally
                        specified}
                    3 - stuff that might help you debug (show all reports)


 Outputs:
   Elements of EEG.iclabel and EEG.history may be changed by the GUI.


 Global Variables:
   VERBLEVEL - level of verbosity (i.e., tells functions how much
               how much to report about what they're doing during
               runtime) set by the optional function argument 'verblevel'
   EEG       - EEGLAB EEG struct variable
    

 Notes: 
 -If you change the label of an IC with the GUI, you need to save the EEG 
 struct variable to disk.  Otherwise, the new label will not be saved with
 the data set.

 -If EEG.icaact (IC activations), EEG.icspectra (IC spectra), or EEG.icfreqs
 (the frequencies corresponding to IC spectra) are empty, this function
 will compute them and add them to the data set.

 -To make sense of IC activations, it is useful to normalize the ICs such
 that they have a maximum absolute topography weight of one.  You can do
 this as follows:
 >> EEG=norm_ics(EEG,'topo abs max');

 Author: 
 David Groppe
 Kutaslab, 11/2009 

 but based largely on EEGLAB pop_prop.m function written by Arnaud Delorme,
 CNL / Salk Institute, 2001

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % ic_prop() - Plots three basic properties of an independent component
0002 %             (topography, ERPimage, spectra) in a GUI that allows the
0003 %             user to change its label (e.g., label it as a particular
0004 %             type of artifact)
0005 %
0006 % Usage:
0007 %  >> ic_prop(ic_num,varargin)
0008 %
0009 % Required Input:
0010 %   ic_num  - [integer | vector of integers] Number(s) of independent
0011 %             component(s) to plot. 1 is the first IC.  The number of the last
0012 %             IC is the number of columns of EEG.icawinv (typically the
0013 %             same as the number of electrodes). If multiple IC numbers are
0014 %             specified, the properties of each IC will plot in a separate window.
0015 %
0016 %
0017 % Optional Inputs:
0018 %   'fig_id'    - [integer | vector of integers] ID number(s) of Matlab
0019 %                 figure windows in which to plot the properties. If ID is
0020 %                 not specified, a new figure window will be generated. If
0021 %                 ic_num is a vector of integers, fig_id can be a vector of
0022 %                 of integers of equal length.  If this is done, the first
0023 %                 IC specified by ic_num will be plot in the first window
0024 %                 specified by fig_id, etc... {default: []}
0025 %   'sortby'    - A string specifying how trials should be sorted when
0026 %                 producing the ERPimage.
0027 %                  Options are:
0028 %                   'logtime' - The time at which the event ocurred
0029 %                       (according to the data's log file).  Earliest event
0030 %                       is drawn at the bottom of the ERPimage. {default}
0031 %                   'logflag' - The artifact code assigned to the trial by
0032 %                        an .arf file. 0=clean trial. 40=nonblink artifact.
0033 %                        60=blink artifact.  Clean trials are drawn at the
0034 %                        bottom of the ERPimage.  Horizontal lines are
0035 %                        drawn to separate trial types.  Useful for making
0036 %                        sure trials have been accurately garved.
0037 %   'from_set_ic_ftr_thresh' - [1 | 0] If 1, ic_prop has been called by the
0038 %                              GUI produced by reject_ics_by_ftr.m and will
0039 %                              update the GUI if changes are made to IC labels.
0040 %                              If 0, no such update is attempted. {default:
0041 %                              0}
0042 %   'verblevel' - An integer specifiying the amount of information you want
0043 %                 functions to provide about what they are doing during runtime.
0044 %                  Options are:
0045 %                    0 - quiet, only show errors, warnings, and EEGLAB reports
0046 %                    1 - stuff anyone should probably know
0047 %                    2 - stuff you should know the first time you start working
0048 %                        with a data set {default value if not already globally
0049 %                        specified}
0050 %                    3 - stuff that might help you debug (show all reports)
0051 %
0052 %
0053 % Outputs:
0054 %   Elements of EEG.iclabel and EEG.history may be changed by the GUI.
0055 %
0056 %
0057 % Global Variables:
0058 %   VERBLEVEL - level of verbosity (i.e., tells functions how much
0059 %               how much to report about what they're doing during
0060 %               runtime) set by the optional function argument 'verblevel'
0061 %   EEG       - EEGLAB EEG struct variable
0062 %
0063 %
0064 % Notes:
0065 % -If you change the label of an IC with the GUI, you need to save the EEG
0066 % struct variable to disk.  Otherwise, the new label will not be saved with
0067 % the data set.
0068 %
0069 % -If EEG.icaact (IC activations), EEG.icspectra (IC spectra), or EEG.icfreqs
0070 % (the frequencies corresponding to IC spectra) are empty, this function
0071 % will compute them and add them to the data set.
0072 %
0073 % -To make sense of IC activations, it is useful to normalize the ICs such
0074 % that they have a maximum absolute topography weight of one.  You can do
0075 % this as follows:
0076 % >> EEG=norm_ics(EEG,'topo abs max');
0077 %
0078 % Author:
0079 % David Groppe
0080 % Kutaslab, 11/2009
0081 %
0082 % but based largely on EEGLAB pop_prop.m function written by Arnaud Delorme,
0083 % CNL / Salk Institute, 2001
0084 %
0085 
0086 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0087 %
0088 % 12/7/2009 Added 'sortby' option. -DG
0089 
0090 % Future Development
0091 % -Make button to plot IC artifact test values, to compute
0092 % IC correction diagnostics, and to restore previous label (maybe)
0093 
0094 function ic_prop(ic_num,varargin)
0095 
0096 
0097 global EEG
0098 global VERBLEVEL
0099 
0100 
0101 %Input Parser
0102 p=inputParser;
0103 %Note: the order of the required arguments needs to match precisely their
0104 %order in the function definition (which is also the order used by p.parse
0105 %below)
0106 p.addRequired('ic_num',@isnumeric);
0107 p.addParamValue('fig_id',[],@(x) isnumeric(x)  || isempty(x));
0108 p.addParamValue('sortby','logtime',@(x) strcmpi('logflag',x)  || strcmpi('logtime',x));
0109 p.addParamValue('verblevel',[],@(x) (x>=0) || isempty(x));
0110 p.addParamValue('from_set_ic_ftr_thresh',0,@isnumeric)
0111 
0112 p.parse(ic_num,varargin{:});
0113 
0114 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0115 % Error check inputs
0116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0117 
0118 if isempty(EEG),
0119     error('To use ic_prop.m there must be an EEG struct global variable called "EEG".  Try typing ">> global EEG" and re-loading your dataset.');
0120 end
0121 
0122 if isempty(EEG.icawinv) && isempty(EEG.icaweights),
0123     error('Current EEG struct does not have ICA components (i.e., EEG.icawinv is empty).  Run ICA.');
0124 end
0125 
0126 if ~isempty(p.Results.verblevel)
0127     VERBLEVEL=p.Results.verblevel;
0128 elseif isempty(VERBLEVEL),
0129     VERBLEVEL=3;
0130 end
0131 
0132 % plotting multiple components?
0133 % -------------------------------------
0134 if length(ic_num) > 1
0135     prop_ct=0;
0136     crnt_vrblvl=VERBLEVEL;
0137     VerbReport(sprintf('Note, if you change any IC labels you will need to save the dataset (i.e., changes are not saved automatically).\n'),2,VERBLEVEL)
0138     for index = ic_num
0139         %Note, no need to resend verblevel
0140         if length(p.Results.fig_id)~=length(ic_num),
0141             if ~isempty(p.Results.fig_id) && (prop_ct==0)
0142                 watchit(sprintf('Number of figure window ID numbers does not equal the number of components whose properties you wish to plot.\nIgnoring figure window IDs.'));
0143             end
0144             ic_prop(index,'verblevel',1,'sortby',p.Results.sortby);
0145         else
0146             prop_ct=prop_ct+1;
0147             ic_prop(index,'fig_id',p.Results.fig_id(prop_ct),'sortby',p.Results.sortby,'verblevel',1);
0148         end
0149     end
0150     VERBLEVEL=crnt_vrblvl;
0151     return;
0152 else
0153     VerbReport(sprintf('Note, if you change any IC labels you will need to save the dataset (i.e., changes are not saved automatically).\n'),2,VERBLEVEL)
0154 end
0155 
0156 if (ic_num < 1) || (ic_num > EEG.nbchan),
0157     error('Component index out of range');
0158 end;
0159 
0160 if ~isempty(p.Results.fig_id)
0161     if length(p.Results.fig_id)>1,
0162         fig_id=p.Results.fig_id(1);
0163     else
0164         fig_id=p.Results.fig_id;
0165     end
0166     if fig_id<0,
0167         error('Argument "fig_id" must be an integer greater than 0.');
0168     end
0169 else
0170     fig_id=[];
0171 end
0172 
0173 
0174 try
0175     icadefs;
0176 catch
0177     BACKCOLOR = [0.8 0.8 0.8];
0178 end;
0179 basename = [EEG.setname ': Component ' int2str(ic_num) ];
0180 
0181 if isempty(EEG.icaact),
0182     VerbReport('Re-computing IC activations from EEG.data, EEG.sphere, and EEG.icaweights.',2,VERBLEVEL);
0183     s=size(EEG.data);
0184     EEG.icaact=reshape(EEG.icaweights*EEG.icasphere*reshape(EEG.data,s(1),s(2)*s(3)),s(1),s(2),s(3));
0185 end
0186 
0187 if ~isempty(fig_id),
0188     fh=figure(fig_id); clf;
0189 else
0190     fh=figure;
0191 end
0192 set(fh,'name', [basename ' properties'], 'color', BACKCOLOR, 'numbertitle', 'off', 'visible', 'off', ...
0193     'MenuBar','none');
0194 pos = get(gcf,'Position');
0195 set(gcf,'Position', [pos(1) pos(2)-500+pos(4) 500 500], 'visible', 'on');
0196 pos = get(gca,'position'); % plot relative to current axes
0197 hh = gca;
0198 q = [pos(1) pos(2) 0 0];
0199 s = [pos(3) pos(4) pos(3) pos(4)]./100;
0200 axis off;
0201 
0202 
0203 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0204 % plotting topoplot
0205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0206 h = axes('Units','Normalized', 'Position',[-10 62 40 42].*s+q);
0207 topoplot( EEG.icawinv(:,ic_num), EEG.chanlocs, ...
0208     'shading', 'interp', 'numcontour', 3); axis square;
0209 
0210 title(['Scalp Map'], 'fontsize', 14,'fontweight','bold','fontname','arial');
0211 mx=max(abs(EEG.icawinv(:,ic_num)));
0212 cbar_topo('vert',0,[-mx mx],3);
0213 
0214 
0215 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0216 % plotting erpimage
0217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0218 hhh = axes('units','normalized', 'position',[0 6 95 44].*s+q);
0219 epoch_order=zeros(1,EEG.trials); %preallocate memory
0220 if strcmpi(p.Results.sortby,'logtime'),
0221     for dgdg=1:EEG.trials
0222         if length(EEG.epoch(dgdg).eventlogitmnum)>1,
0223             epoch_order(dgdg)=EEG.epoch(dgdg).eventlogitmnum{1};
0224         else
0225             epoch_order(dgdg)=EEG.epoch(dgdg).eventlogitmnum;
0226         end
0227     end
0228 elseif strcmpi(p.Results.sortby,'logflag'),
0229     for dgdg=1:EEG.trials
0230         if length(EEG.epoch(dgdg).eventlogflag)>1,
0231             epoch_order(dgdg)=EEG.epoch(dgdg).eventlogflag{1};
0232         else
0233             epoch_order(dgdg)=EEG.epoch(dgdg).eventlogflag;
0234         end
0235     end
0236     bndries=[sum(epoch_order==0) (sum(epoch_order==0)+sum(epoch_order==40))];
0237     bndries=unique(bndries);
0238 end
0239 eeg_options;
0240 % put title at top of ERPimage
0241 axis off
0242 hh = axes('units','normalized', 'position',[0 6 95 44].*s+q);
0243 if EEG.trials < 6
0244     ei_smooth = 0;
0245 else
0246     ei_smooth = 2;
0247 end
0248 
0249 era=nan_mean(squeeze(EEG.icaact(ic_num,:,:))');
0250 mn=min(era);
0251 mx=max(era);
0252 mn=orderofmag(mn)*round(mn/orderofmag(mn));
0253 mx=orderofmag(mx)*round(mx/orderofmag(mx));
0254 era_limits=[mn mx];
0255 if strcmpi(p.Results.sortby,'logtime'),
0256     erpimage( squeeze(EEG.icaact(ic_num,:,:)), ...
0257         epoch_order, EEG.times , '', ei_smooth,0, 'cbar','erp', 'yerplabel', '\muV','noplot','cbar_title','\muV','avg_type','Gaussian','erp_vltg_ticks',era_limits);
0258 elseif strcmpi(p.Results.sortby,'logflag'),
0259     erpimage( squeeze(EEG.icaact(ic_num,:,:)), ...
0260         epoch_order, EEG.times , '', ei_smooth,0, 'cbar','erp', 'yerplabel', ...
0261         '\muV','noplot','cbar_title','\muV','avg_type','Gaussian','erp_vltg_ticks', ...
0262         era_limits,'horz',bndries);
0263 end
0264 axes(hhh);
0265 title(['Activity (ERPimage and ERP)'], 'fontsize', 14,'fontweight','bold','fontname','arial');
0266 
0267 
0268 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0269 % plotting spectrum
0270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0271 h = axes('Units','Normalized', 'Position',[60 70 48*.8 38*.8].*s+q);
0272 try
0273     eeg_options;
0274     
0275     if ~isfield(EEG,'icspectra') || ~isfield(EEG,'icfreqs'), 
0276         VerbReport('This data set is missing IC spectra.',2,VERBLEVEL);
0277         VerbReport('Computing spectra for all ICs and adding fields EEG.icspectra and EEG.icfreqs.',2,VERBLEVEL);
0278         [EEG.icspectra, EEG.icfreqs] = spectopo( EEG.icaact, EEG.pnts, EEG.srate,'plot','off');
0279         EEG.saved='no';
0280     end
0281     
0282     % set new axis limits
0283     % -----------------
0284     freqslim = 80;
0285     use_freqs=find(EEG.icfreqs <= freqslim);
0286     spectra = EEG.icspectra(ic_num,use_freqs);
0287     h_spec=plot(EEG.icfreqs(use_freqs),spectra,'r');
0288     set(h_spec,'linewidth',2);
0289     set(gca, 'ylim', [min(spectra) max(spectra)]);
0290     set(gca, 'xlim', [0 min(freqslim, EEG.srate/2)],'xtick',[0:10:freqslim],'fontsize',10);
0291     h=ylabel('10*log_1_0(\muV^2/Hz)','fontsize', 12,'fontname','times','fontweight','bold'); %units are default ylabel from spectopo
0292     set( get(gca, 'xlabel'), 'string', 'Frequency (Hz)', 'fontsize', 12,'fontname','times','fontweight','bold');
0293     title('Activity Power Spectrum', 'fontsize', 14, 'fontweight','bold','fontname','arial');
0294 catch
0295     axis off;
0296     text(0.1, 0.3, [ 'Error: no spectrum plotted' 10 ' make sure you have the ' 10 'signal processing toolbox']);
0297 end;
0298 
0299 
0300 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0301 % Figure Buttons
0302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0303 
0304 %full set filename
0305 if isempty(EEG.filepath)
0306     setfname=EEG.filename;
0307 elseif EEG.filepath(end)=='/',
0308     setfname=[EEG.filepath EEG.filename];
0309 else
0310     setfname=[EEG.filepath '/' EEG.filename];
0311 end
0312 
0313 %Some Possible IC labels
0314 label_libry{1}='None';
0315 label_libry{2}='Blink';
0316 label_libry{3}='HE';
0317 label_libry{4}='EOG';
0318 label_libry{5}='EMG';
0319 label_libry{6}='Heart';
0320 label_libry{7}='Drift';
0321 label_libry{8}='Bad_chan';
0322 label_libry{9}='60HZ';
0323 label_libry{10}='Art';
0324 
0325 
0326 %Get existing IC label
0327 fldnms=fieldnames(EEG);
0328 iclabels_on=0;
0329 for floop=1:length(fldnms),
0330     if strcmpi(fldnms{floop},'iclabels'),
0331         iclabels_on=1;
0332         break;
0333     end
0334 end
0335 if iclabels_on,
0336     if length(EEG.iclabels)>=ic_num,
0337         if isempty(EEG.iclabels{ic_num}),
0338             cur_label='None';
0339         else
0340             cur_label=EEG.iclabels{ic_num};
0341             label_in_libry=1;
0342             %Add label to library of possible names if it's not already
0343             %there
0344             for floop=1:length(label_libry),
0345                 if strcmpi(label_libry{floop},cur_label)
0346                     label_in_libry=1;
0347                     break;
0348                 end
0349             end
0350             if ~label_in_libry,
0351                 label_libry{length(label_libry)+1}=cur_label;
0352             end
0353         end
0354     else
0355         cur_label='None';
0356         EEG.iclabels{ic_num}=[];
0357     end
0358 else
0359     cur_label='None';
0360     EEG.iclabels{ic_num}=[];
0361 end
0362     
0363 % CLOSE button
0364 % -------------
0365 h=uicontrol(gcf, 'Style', 'pushbutton', 'string', 'Close', 'Units','Normalized','Position',[-13 -12 15 8].*s+q,'fontsize',12,'callback', 'close(gcf);');
0366 
0367 % Create label menu button
0368 % ------------------------
0369 % Note: Callback on this button does the following:
0370 %  1) check to make sure there's a global EEG variable in memory
0371 %  2) check to make sure the participant name and filename match between
0372 %  the figure and the EEG variable in memory
0373 %  3) update the IC's label
0374 %  4) add change of label to EEG.history and mark EEG variable as in need of saving
0375 %  5) enable all the "save" buttons on any currently open ic_prop figure
0376 %  from this participant and filename
0377 if p.Results.from_set_ic_ftr_thresh,
0378     cback_line=' set_ic_ftr_thresh(''new feature'');';
0379 else
0380     cback_line=[];
0381 end
0382 h_labB=uicontrol(fh,...
0383     'CallBack',['dat_tmp=get(gcf,''UserData''); ' ...
0384     ' global EEG; ', ...
0385     ' [tmps,ok] = listdlg(''PromptString'', ''Select Label'', ''SelectionMode'',''single'',''ListString'', dat_tmp.label_libry);' ...
0386     ' if ok, ' ...
0387     '    set(dat_tmp.h_lab, ''string'', dat_tmp.label_libry{tmps}); ' ...
0388     ' end; ' ...
0389     ' if exist(''EEG'',''var''), ', ...    
0390     '   if isempty(EEG.filepath), ', ...
0391     '     fname=EEG.filename; ', ...
0392     '   elseif (EEG.filepath(end)==''/''),', ...
0393     '     fname=[EEG.filepath EEG.filename];', ...
0394     '   else ', ...
0395     '     fname=[EEG.filepath ''/'' EEG.filename]; ', ...
0396     '   end; ', ...
0397     '   if strcmpi(fname,dat_tmp.setfname), ', ...
0398     '      EEG.iclabels{dat_tmp.ic_num}=get(dat_tmp.h_lab,''string''); ', ...
0399     '   else, ', ...
0400     '      error(''Current figure and global EEG variable were produced by different files. No changes will be made to IC labels.''); ', ...
0401     '   end; ', ...
0402     ' else', ...
0403     '   error(''The EEG variable that produced this figure needs to be global.  Try typing ">> global EEG"''); ', ...
0404     ' end; ', ...
0405     ' EEG.saved=''no''; ', ...
0406     ' if is_art(EEG.iclabels{dat_tmp.ic_num}), ' ...
0407     '   if ~EEG.reject.gcompreject(dat_tmp.ic_num), ' ...
0408     '     EEG.reject.gcompreject(dat_tmp.ic_num)=1; ', ...
0409     '     EEG.history=[EEG.history 10 ''EEG.reject.gcompreject('' num2str(dat_tmp.ic_num) '')=1;'']; ', ...
0410     '   end; ' ...
0411     ' else, ' ...
0412     '   if EEG.reject.gcompreject(dat_tmp.ic_num), ' ...
0413     '     EEG.reject.gcompreject(dat_tmp.ic_num)=0; ', ...
0414     '     EEG.history=[EEG.history 10 ''EEG.reject.gcompreject('' num2str(dat_tmp.ic_num) '')=0;''];', ...
0415     '   end; ' ...
0416     ' end; ' ...
0417     ' EEG.history=[EEG.history 10 ''EEG.iclabels{'' num2str(dat_tmp.ic_num) ''}='' 39 dat_tmp.label_libry{tmps} 39 '';''];', ...
0418     ' h_figs = get(0,''children'')''; ' ...
0419     ' for a=h_figs ', ...
0420     '   userdata=get(a,''userdata'');' ...
0421     '   if isfield(userdata,''setname'') && isfield(userdata,''setfname''), ' ...
0422     '     if strcmp(userdata.setname,dat_tmp.setname) && strcmp(userdata.setfname,dat_tmp.setfname), ' ...
0423     '       set(userdata.h_save,''enable'',''on''); ' ...
0424     '     end; ' ...
0425     '   end; ' ...
0426     ' end; ' ...
0427     cback_line, ...
0428     ' clear tmps ok dat_tmp;'], ...
0429     'Units','normalized', ...
0430     'Position',[5 -12 15 8].*s+q,...
0431     'String','Label:',...
0432     'Style','pushbutton', ...
0433     'Fontsize',12, ...
0434     'enable','on', ...
0435     'ToolTipString',sprintf('Click button for list of possible IC labels.'),...
0436     'horizontalalignment','center', ...
0437     'tag','labB');
0438     
0439     
0440 
0441 
0442 % Create Label text box
0443 % ---------------------
0444 % Note: Callback on this box does the following:
0445 %  1) check to make sure there's a global EEG variable in memory
0446 %  2) check to make sure the participant name and filename match between
0447 %  the figure and the EEG variable in memory
0448 %  3) update the IC's label
0449 %  4) enable all the "save" buttons on any currently open ic_prop figure
0450 %  from this participant and filename
0451 %  5) add change of label to EEG.history and mark EEG variable as in need of saving
0452 %  6) update EEG.reject.gcompreject (the EEGLAB binary field which labels
0453 %     ICs as artifacts) and add to history
0454 h_lab=uicontrol(fh,...
0455     'CallBack',[ ...
0456     ' if exist(''EEG'',''var''), ', ...
0457     '   dat_tmp=get(gcf,''UserData''); ', ...
0458     '   if isempty(EEG.filepath), ', ...
0459     '     fname=EEG.filename; ', ...
0460     '   elseif (EEG.filepath(length(EEG.filepath))==''/''), ', ...
0461     '     fname=[EEG.filepath EEG.filename]; ', ...
0462     '   else ', ...
0463     '     fname=[EEG.filepath ''/'' EEG.filename]; ', ...
0464     '   end; ', ...
0465     '   if strcmpi(fname,dat_tmp.setfname), ', ...
0466     '      EEG.iclabels{dat_tmp.ic_num}=get(dat_tmp.h_lab,''string''); ', ...
0467     '   else, ', ...
0468     '      error(''Current figure and global EEG variable were produced by different files.''); ', ...
0469     '   end; ', ...
0470     ' else', ...
0471     '   error(''The EEG variable that produced this figure needs to be global.  Try typing ">> global EEG"''); ', ...
0472     ' end; ', ...
0473     ' h_figs = get(0,''children'')''; ' ...
0474     ' for a=h_figs ', ...
0475     '   userdata=get(a,''userdata'');' ...
0476     '   if isfield(userdata,''setname'') && isfield(userdata,''setfname''), ' ...
0477     '     if strcmp(userdata.setname,dat_tmp.setname) && strcmp(userdata.setfname,dat_tmp.setfname), ' ...
0478     '       set(userdata.h_save,''enable'',''on''); ' ...
0479     '     end; ' ...
0480     '   end; ' ...
0481     ' end; ' ...
0482     ' EEG.saved=''no''; ', ...
0483     ' EEG.history=[EEG.history 10 ''EEG.iclabels{'' num2str(dat_tmp.ic_num) ''}='' 39 EEG.iclabels{dat_tmp.ic_num} 39 '';''];', ...
0484     ' if is_art(EEG.iclabels{dat_tmp.ic_num}), ' ...
0485     '   if ~EEG.reject.gcompreject(dat_tmp.ic_num), ' ...
0486     '     EEG.reject.gcompreject(dat_tmp.ic_num)=1; ', ...
0487     '     EEG.history=[EEG.history 10 ''EEG.reject.gcompreject('' num2str(dat_tmp.ic_num) '')=1;'']; ', ...
0488     '   end; ' ...
0489     ' else, ' ...
0490     '   if EEG.reject.gcompreject(dat_tmp.ic_num), ' ...
0491     '     EEG.reject.gcompreject(dat_tmp.ic_num)=0; ', ...
0492     '     EEG.history=[EEG.history 10 ''EEG.reject.gcompreject('' num2str(dat_tmp.ic_num) '')=0;''];', ...
0493     '   end; ' ...
0494     ' end; ' ...
0495      cback_line, ...
0496     ' clear dat_tmp h_figs a userdata;'], ...
0497     'Units','normalized', ...
0498     'Position',[20 -12 20 8].*s+q,...
0499     'String',cur_label,...
0500     'Style','edit', ...
0501     'Fontsize',12, ...
0502     'enable','on', ...
0503     'backgroundcolor','w', ...
0504     'horizontalalignment','center', ...
0505     'ToolTipString',sprintf('Enter desired IC label here.'),...
0506     'tag','lab');
0507 
0508 % Create Save Dataset button
0509 % --------------------------
0510 % Note: Callback on this button does the following:
0511 %  1) check to make sure there's a global EEG variable in memory
0512 %  2) check to make sure the participant name and filename match between
0513 %  the figure and the EEG variable in memory
0514 %  3) save the EEG variable in memory to disk
0515 %  4) dis-enable all the "save" buttons on any currently open ic_prop figure
0516 %  from this participant and filename
0517 if strcmpi(EEG.saved,'no'),
0518     enable_status='on';
0519 else
0520     %saved is either 'yes' or 'justloaded' (I believe)
0521     enable_status='off';
0522 end
0523 h_save=uicontrol(fh,...
0524     'CallBack',['if exist(''EEG'',''var''), ', ...
0525     '   dat_tmp=get(gcf,''UserData''); ' ...
0526     '   if isempty(EEG.filepath), ', ...
0527     '     fname=EEG.filename; ', ...
0528     '   elseif (EEG.filepath(end)==''/''),', ...
0529     '     fname=[EEG.filepath EEG.filename];', ...
0530     '   else ', ...
0531     '     fname=[EEG.filepath ''/'' EEG.filename]; ', ...    
0532     '   end; ', ...
0533     '   if strcmpi(fname,dat_tmp.setfname), ', ...
0534     '      EEG=pop_saveset(EEG,''savemode'',''resave''); ', ...
0535     '      EEG.saved=''yes''; ', ...
0536     '      h_figs = get(0,''children'')''; ' ...
0537     '      for a=h_figs ', ...
0538     '        userdata=get(a,''userdata'');' ...
0539     '        if isfield(userdata,''setname'') && isfield(userdata,''setfname''), ' ...
0540     '          if strcmp(userdata.setname,dat_tmp.setname) && strcmp(userdata.setfname,dat_tmp.setfname), ' ...
0541     '            set(userdata.h_save,''enable'',''off''); ' ...
0542     '          end; ' ...
0543     '        end; ' ...
0544     '      end; ' ...
0545     '   else, ', ...
0546     '      error(''Current figure and global EEG variable were produced by different files.''); ', ...
0547     '   end; ', ...
0548     ' else', ...
0549     '   error(''The EEG variable that produced this figure needs to be global.  Try typing ">> global EEG"''); ', ...
0550     ' end; ', ...
0551     ' clear dat_tmp;'], ...
0552     'Units','normalized', ...
0553     'Position',[43 -12 15 8].*s+q,...
0554     'String','Save:',...
0555     'Style','pushbutton', ...
0556     'Fontsize',12, ...
0557     'enable',enable_status, ...
0558     'ToolTipString',sprintf('Push button to save current dataset to disk.'),...
0559     'horizontalalignment','center', ...
0560     'tag','save');
0561 
0562 % filename
0563 h_fname=uicontrol(fh,...
0564     'Units','normalized', ...
0565     'Position',[58 -11.5 53 6].*s+q,...
0566     'String',EEG.filename,...
0567     'backgroundcolor',BACKCOLOR, ...
0568     'Style','text', ...
0569     'Fontsize',12, ...
0570     'ToolTipString',sprintf('This IC was taken from: %s.',setfname),...
0571     'horizontalalignment','left', ...
0572     'tag','save');
0573 
0574 
0575 dat_tmp=get(fh,'userdata');
0576 dat_tmp.label_libry=label_libry;
0577 dat_tmp.h_lab=h_lab;
0578 dat_tmp.h_labB=h_labB;
0579 dat_tmp.h_save=h_save;
0580 dat_tmp.h_fname=h_fname;
0581 dat_tmp.setfname=setfname;
0582 dat_tmp.setname=EEG.setname;
0583 dat_tmp.ic_num=ic_num;
0584 set(fh,'userdata',dat_tmp);
0585 
0586 
0587 clear
0588 return;
0589 
0590 function out = nan_mean(in)
0591 
0592 nans = find(isnan(in));
0593 in(nans) = 0;
0594 sums = sum(in);
0595 nonnans = ones(size(in));
0596 nonnans(nans) = 0;
0597 nonnans = sum(nonnans);
0598 nononnans = find(nonnans==0);
0599 nonnans(nononnans) = 1;
0600 out = sum(in)./nonnans;
0601 out(nononnans) = NaN;
0602 
0603 
0604 function ord=orderofmag(val)
0605 %function ord=orderofmag(val)
0606 %
0607 % Returns the order of magnitude of the value of 'val' in multiples of 10
0608 % (e.g., 10^-1, 10^0, 10^1, 10^2, etc ...)
0609 % used for computing erpimage trial axis tick labels as an alternative for
0610 % plotting sorting variable
0611 
0612 val=abs(val);
0613 if val>=1
0614     ord=1;
0615     val=floor(val/10);
0616     while val>=1,
0617         ord=ord*10;
0618         val=floor(val/10);
0619     end
0620     return;
0621 else
0622     ord=1/10;
0623     val=val*10;
0624     while val<1,
0625         ord=ord/10;
0626         val=val*10;
0627     end
0628     return;
0629 end

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