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
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 function ic_prop(ic_num,varargin)
0095
0096
0097 global EEG
0098 global VERBLEVEL
0099
0100
0101
0102 p=inputParser;
0103
0104
0105
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
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
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
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');
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
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
0217
0218 hhh = axes('units','normalized', 'position',[0 6 95 44].*s+q);
0219 epoch_order=zeros(1,EEG.trials);
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
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
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
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');
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
0302
0303
0304
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
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
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
0343
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
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
0368
0369
0370
0371
0372
0373
0374
0375
0376
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
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
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
0509
0510
0511
0512
0513
0514
0515
0516
0517 if strcmpi(EEG.saved,'no'),
0518 enable_status='on';
0519 else
0520
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
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
0606
0607
0608
0609
0610
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