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
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 function gui_erp(cmnd_str,varargin)
0331
0332 p=inputParser;
0333 p.addRequired('cmnd_str',@(x) ischar(x) || isstruct(x));
0334 p.addParamValue('fig_id',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1)));
0335 p.addParamValue('bin',1,@(x) isnumeric(x) && (length(x)==1));
0336 p.addParamValue('show_wind',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==2)));
0337 p.addParamValue('GNDorGRP',[],@isstruct);
0338 p.addParamValue('critical_t',[],@(x) isempty(x) || (isnumeric(x) && (length(x)<=2)));
0339 p.addParamValue('test_wind',[],@(x) isempty(x) || (isnumeric(x) && (size(x,2)==2)));
0340 p.addParamValue('ydir',-1,@(x) isnumeric(x) && (length(x)==1));
0341 p.addParamValue('stat','t',@(x) ischar(x) || strcmpi(x,'t') || strcmpi(x,'stder'));
0342 p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0343 p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0344 p.addParamValue('alpha_or_q',[],@(x) isempty(x) || isnumeric(x));
0345 p.addParamValue('t_test',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1) && (x>0)));
0346 p.addParamValue('verblevel',2,@(x) isnumeric(x) && (length(x)==1));
0347 p.parse(cmnd_str,varargin{:});
0348
0349
0350 if isstruct(cmnd_str)
0351
0352
0353
0354 gui_erp('initialize','GNDorGRP',cmnd_str,'fig_id',p.Results.fig_id, ...
0355 'bin',p.Results.bin, ...
0356 'critical_t',p.Results.critical_t, ...
0357 'test_wind',p.Results.test_wind, ...
0358 'show_wind',p.Results.show_wind, ...
0359 'ydir',p.Results.ydir, ...
0360 'stat',p.Results.stat, ...
0361 'exclude_chans',p.Results.exclude_chans, ...
0362 'include_chans',p.Results.include_chans, ...
0363 'alpha_or_q',p.Results.alpha_or_q, ...
0364 't_test',p.Results.t_test, ...
0365 'verblevel',p.Results.verblevel);
0366 return;
0367 end
0368
0369
0370 psbl_cmnds{1}='initialize';
0371 psbl_cmnds{2}='time jump';
0372 psbl_cmnds{3}='back one';
0373 psbl_cmnds{4}='forward one';
0374 psbl_cmnds{5}='back';
0375 psbl_cmnds{6}='forward';
0376 psbl_cmnds{7}='change stat';
0377 psbl_cmnds{8}='new time limits';
0378 psbl_cmnds{9}='new statistic limitsA';
0379 psbl_cmnds{10}='change bin';
0380 psbl_cmnds{11}='new statistic limitsB';
0381 psbl_cmnds{12}='update dashed lines';
0382 psbl_cmnds{13}='update critical t';
0383 psbl_cmnds{14}='redraw topo';
0384 psbl_cmnds{15}='change test';
0385 if ~ismember(cmnd_str,psbl_cmnds),
0386 error('''%s'' is not a valid value of cmnd_str for gui_erp.m',cmnd_str);
0387 end
0388
0389
0390 if ~strcmp(cmnd_str,'initialize')
0391 if isempty(p.Results.fig_id),
0392 fig_id=gcbf;
0393 else
0394 fig_id=p.Results.fig_id;
0395 end
0396 if ~strcmp(get(fig_id,'tag'),'gui_erp')
0397
0398
0399 h_figs = get(0,'children');
0400 fig_id = findobj(h_figs,'flat',...
0401 'tag','gui_erp');
0402 if isempty(fig_id),
0403
0404
0405
0406 gui_erp('initialize');
0407 gui_erp(cmnd_str);
0408 return;
0409 end
0410 end
0411
0412
0413
0414
0415
0416
0417
0418 dat=get(gcbf,'userdata');
0419 end
0420
0421
0422 if isempty(p.Results.verblevel),
0423 VERBLEVEL=2;
0424 else
0425 VERBLEVEL=p.Results.verblevel;
0426 end
0427
0428
0429 if strcmp(cmnd_str,'initialize')
0430 if isempty(p.Results.GNDorGRP.grands)
0431 error('There are no bins (i.e., ERPs) in this GND or GRP variable. You need to add bins before you can visualize them with the ERP GUI.');
0432 end
0433
0434
0435 if isempty(p.Results.fig_id),
0436 dat.fig_id=figure;
0437 else
0438 dat.fig_id=p.Results.fig_id;
0439 figure(dat.fig_id);
0440 clf
0441 end
0442 set(dat.fig_id,'name',['ERP GUI ' p.Results.GNDorGRP.exp_desc],'tag','gui_erp', ...
0443 'MenuBar','none','position',[139 42 690 700]);
0444
0445
0446 n_t_tests=length(p.Results.GNDorGRP.t_tests);
0447 dat.psbl_tests=[];
0448 temp_bins=zeros(1,n_t_tests);
0449 for d=1:n_t_tests,
0450 if ~strcmpi(p.Results.GNDorGRP.t_tests(d).mean_wind,'yes'),
0451 dat.psbl_tests=[dat.psbl_tests d];
0452 temp_bins(d)=p.Results.GNDorGRP.t_tests(d).bin;
0453 end
0454 end
0455 temp_bins=temp_bins(dat.psbl_tests);
0456 n_psbl_tests=length(dat.psbl_tests);
0457 dat.t_tests=p.Results.GNDorGRP.t_tests(dat.psbl_tests);
0458 crnt_ttest=n_psbl_tests+1;
0459
0460 use_ttest=0;
0461 if isempty(p.Results.t_test),
0462 if isempty(p.Results.include_chans) && isempty(p.Results.exclude_chans) ...
0463 && isempty(p.Results.critical_t) && isempty(p.Results.alpha_or_q) ...
0464 && isempty(p.Results.test_wind),
0465
0466
0467
0468 test_ids=find(p.Results.bin==temp_bins);
0469 if ~isempty(test_ids),
0470 use_ttest=1;
0471 crnt_ttest=test_ids(1);
0472 if VERBLEVEL>=2
0473 fprintf('Plotting results of t-tests set %d. Any input arguments (e.g., ''critical_t'') inconsistent with this test will be ignored.\n', ...
0474 dat.psbl_tests(crnt_ttest));
0475 end
0476 end
0477 end
0478 else
0479 if p.Results.t_test>n_t_tests,
0480 error('Argument ''t_test'' value of %d exceeds the number of test results stored in this GND/GRP variable (i.e., %d).', ...
0481 p.Results.t_test,n_t_tests);
0482 elseif ~ismember(p.Results.t_test,dat.psbl_tests),
0483 error('t-test set %d in this GND/GRP variable was performed on mean amplitudes within one or more time windows. You cannot visualize such tests with gui_erp.m.', ...
0484 p.Results.t_test);
0485 else
0486 use_ttest=1;
0487 crnt_ttest=find(dat.psbl_tests==p.Results.t_test);
0488 if VERBLEVEL>=2
0489 fprintf('Plotting results of t-test set %d. Any input arguments (e.g., ''bin'') inconsistent with this test will be ignored.\n', ...
0490 p.Results.t_test);
0491 end
0492 end
0493 end
0494 if use_ttest,
0495
0496
0497 bin=dat.t_tests(crnt_ttest).bin;
0498 if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
0499 dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
0500 dat.mltplcmp_crct='fdr';
0501 else
0502 dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
0503 dat.mltplcmp_crct='perm';
0504 end
0505 test_wind=dat.t_tests(crnt_ttest).time_wind;
0506 dat.n_wind=size(test_wind,1);
0507 include_chans=dat.t_tests(crnt_ttest).include_chans;
0508 dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
0509 dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
0510 else
0511
0512 bin=p.Results.bin;
0513 test_wind=p.Results.test_wind;
0514 include_chans=p.Results.include_chans;
0515 dat.alpha=p.Results.alpha_or_q;
0516 dat.critical_t=p.Results.critical_t;
0517 dat.null_mean=0;
0518 end
0519
0520
0521
0522
0523 if bin>length(p.Results.GNDorGRP.bin_info)
0524 close(gcf);
0525 error('You asked to visualize Bin %d, but your GND/GRP variable only contains %d bins.', ...
0526 bin,length(p.Results.GNDorGRP.bin_info));
0527 elseif (isfield(p.Results.GNDorGRP,'sub_ct') && ~p.Results.GNDorGRP.sub_ct(bin)) || ...
0528 (isfield(p.Results.GNDorGRP.bin_info(bin),'n_subsA') && ( ~p.Results.GNDorGRP.bin_info(bin).n_subsA || ~p.Results.GNDorGRP.bin_info(bin).n_subsB))
0529 close(gcf);
0530 error('You asked to visualize Bin %d, but your GND/GRP variable doesn''t have any data in that bin.', ...
0531 bin);
0532 end
0533
0534
0535 n_chan=length(p.Results.GNDorGRP.chanlocs);
0536
0537 if ~isempty(include_chans) && ~isempty(p.Results.exclude_chans)
0538 if use_ttest,
0539 error('You cannot specify a set of t-tests to visualize and use the ''exclude_chans'' option.');
0540 else
0541 error('You cannot use BOTH ''include_chans'' and ''exclude_chans'' options.');
0542 end
0543 end
0544 if ischar(p.Results.exclude_chans),
0545 exclude_chans{1}=p.Results.exclude_chans;
0546 elseif isempty(p.Results.exclude_chans)
0547 exclude_chans=[];
0548 else
0549 exclude_chans=p.Results.exclude_chans;
0550 end
0551 if ischar(include_chans),
0552 temp_var=include_chans;
0553 clear include_chans;
0554 include_chans{1}=temp_var;
0555 clear temp_var;
0556 end
0557 if ~isempty(exclude_chans),
0558 ignore_chans=zeros(1,length(exclude_chans));
0559 ct=0;
0560 for x=1:length( exclude_chans),
0561 found=0;
0562 for c=1:n_chan,
0563 if strcmpi(exclude_chans{x},p.Results.GNDorGRP.chanlocs(c).labels),
0564 found=1;
0565 ct=ct+1;
0566 ignore_chans(ct)=c;
0567 end
0568 end
0569 if ~found,
0570 watchit(sprintf('I attempted to exclude %s. However no such electrode was found in GND/GRP variable.', ...
0571 exclude_chans{x}));
0572 end
0573 end
0574 ignore_chans=ignore_chans(1:ct);
0575 loaded_chans=setdiff(1:n_chan,ignore_chans);
0576 elseif ~isempty(include_chans),
0577 loaded_chans=zeros(1,length(include_chans));
0578 ct=0;
0579 for x=1:length(include_chans),
0580 found=0;
0581 for c=1:n_chan,
0582 if strcmpi(include_chans{x},p.Results.GNDorGRP.chanlocs(c).labels),
0583 found=1;
0584 ct=ct+1;
0585 loaded_chans(ct)=c;
0586 end
0587 end
0588 if ~found,
0589 watchit(sprintf('I attempted to include %s. However no such electrode was found in GND/GRP variable.', ...
0590 include_chans{x}));
0591 end
0592 end
0593 loaded_chans=loaded_chans(1:ct);
0594 else
0595 loaded_chans=1:n_chan;
0596 end
0597 if isempty(loaded_chans),
0598 error('No channels selected for visualization!');
0599 end
0600
0601 yes_coord=zeros(1,n_chan);
0602 for c=loaded_chans,
0603 if ~isempty(p.Results.GNDorGRP.chanlocs(c).theta) && ~isnan(p.Results.GNDorGRP.chanlocs(c).theta)
0604 yes_coord(c)=1;
0605 end
0606 end
0607 if (sum(yes_coord)==0)
0608 if use_ttest
0609
0610 watchit(sprintf('None of the channels you wish to visualize have scalp coordinates.\nIt is pointless to use the ERP GUI. Using sig_wave.m instead.'));
0611 close(gcf);
0612 sig_wave(p.Results.GNDorGRP,crnt_ttest,'ydir',p.Results.ydir, ...
0613 'verblevel',p.Results.verblevel);
0614 else
0615 watchit('None of the channels you wish to visualize have scalp coordinates. It is pointless to use the ERP GUI. Using plot_wave.m instead.');
0616 close(gcf);
0617 if ~isempty(include_chans),
0618 plot_wave(p.Results.GNDorGRP,bin,'ydir',p.Results.ydir, ...
0619 'verblevel',p.Results.verblevel,'include_chans',include_chans);
0620 else
0621
0622
0623 plot_wave(p.Results.GNDorGRP,bin,'ydir',p.Results.ydir, ...
0624 'verblevel',p.Results.verblevel,'exclude_chans',exclude_chans);
0625 end
0626 end
0627 return
0628 elseif sum(yes_coord)<length(loaded_chans),
0629 watchit(sprintf('%d channels do not have scalp coordinates. The waveforms for such channels will be visualized but they the will not be represented in the scalp topography.', ...
0630 length(loaded_chans)-sum(yes_coord)));
0631 end
0632
0633
0634
0635 use_tests=[];
0636 for d=1:n_psbl_tests,
0637 if ~isempty(intersect(loaded_chans,dat.t_tests(d).used_chan_ids)),
0638 use_tests=[use_tests d];
0639 end
0640 end
0641 dat.psbl_tests=dat.psbl_tests(use_tests);
0642 dat.t_tests=dat.t_tests(use_tests);
0643 crnt_ttest=find(crnt_ttest==[use_tests n_psbl_tests+1]);
0644 n_psbl_tests=length(use_tests);
0645
0646
0647 dat.erp=p.Results.GNDorGRP.grands;
0648 dat.t_scores=p.Results.GNDorGRP.grands_t;
0649 dat.stder=p.Results.GNDorGRP.grands_stder;
0650 mn_erp_across_chans=mean(dat.erp,1);
0651 dat.gfp=squeeze(sqrt(mean( (dat.erp-repmat(mn_erp_across_chans,[n_chan 1 1])).^2,1)));
0652
0653 if (crnt_ttest<=n_psbl_tests) && (dat.t_tests(crnt_ttest).null_mean),
0654
0655 dat.showing_t=squeeze( (p.Results.GNDorGRP.grands(loaded_chans,:,bin)- ...
0656 dat.t_tests(crnt_ttest).null_mean)./p.Results.GNDorGRP.grands_stder(loaded_chans,:,bin) );
0657 else
0658 dat.showing_t=squeeze(p.Results.GNDorGRP.grands_t(loaded_chans,:,bin));
0659 end
0660
0661 if isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)) || strcmpi(p.Results.stat,'gfp'),
0662
0663
0664
0665
0666
0667 dat.showingB=dat.gfp(:,bin)';
0668 elseif strcmpi(p.Results.stat,'t'),
0669 dat.showingB=dat.showing_t;
0670 else
0671
0672 dat.showingB=squeeze(p.Results.GNDorGRP.grands_stder(loaded_chans,:,bin));
0673 end
0674 dat.showingA=squeeze(p.Results.GNDorGRP.grands(loaded_chans,:,bin));
0675
0676 n_bin=length(p.Results.GNDorGRP.bin_info);
0677 dat.bindesc=cell(1,n_bin);
0678 for b=1:n_bin,
0679 dat.bindesc{b}=p.Results.GNDorGRP.bin_info(b).bindesc;
0680 end
0681 dat.times=p.Results.GNDorGRP.time_pts;
0682 if isempty(p.Results.show_wind),
0683 dat.plt_times=[p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)];
0684 else
0685 dat.plt_times=p.Results.show_wind;
0686 end
0687 dat.chanlocs=p.Results.GNDorGRP.chanlocs;
0688 dat.loaded_chans=loaded_chans;
0689 dat.showing_chans=loaded_chans;
0690 critical_t=dat.critical_t;
0691 ydir=p.Results.ydir;
0692 if length(critical_t)>2,
0693 critical_t=critical_t(1:2);
0694 end
0695 dat.critical_t=critical_t;
0696
0697
0698
0699
0700
0701 frm_col=[1 1 1]*.702;
0702 uipanel(dat.fig_id,...
0703 'Units','normalized', ...
0704 'Position',[ 0 0.59 .72 0.42 ],...
0705 'shadowcolor','k', ...
0706 'highlightcolor',frm_col, ...
0707 'foregroundcolor',frm_col, ...
0708 'backgroundcolor',frm_col);
0709
0710 dat.h_timeA=axes('position',[0.1 .62 .6 .33]);
0711 dat.start_pt=find_tpt(dat.plt_times(1),dat.times);
0712 dat.end_pt=find_tpt(dat.plt_times(2),dat.times);
0713 plotted_pts=dat.start_pt:dat.end_pt;
0714 plotted_times=dat.times(dat.start_pt:dat.end_pt);
0715 [dat.absmxA mx_tpt]=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
0716 stat_mx=max(max(dat.showingA(:,dat.start_pt:dat.end_pt)));
0717 stat_mn=min(min(dat.showingA(:,dat.start_pt:dat.end_pt)));
0718 stat_rng=stat_mx-stat_mn;
0719 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
0720 stat_plt_rng=round(stat_plt_rng*100)/100;
0721 plot([p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)],[0 0],'k');
0722 hold on;
0723 dat.h_t0lineA=plot([0 0],stat_plt_rng,'k');
0724 set(dat.h_timeA,'ygrid','on');
0725 if ydir<0,
0726 set(dat.h_timeA,'ydir','reverse');
0727 end
0728 if size(dat.showingA,1)==1,
0729
0730 dat.h_showingA=plot(dat.times,dat.showingA);
0731 else
0732 dat.h_showingA=plot(dat.times,dat.showingA');
0733 end
0734 axis tight;
0735 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
0736 vA=axis;
0737 dat.h_lineA=plot([1 1]*plotted_times(mx_tpt),vA(3:4),'k');
0738 set(dat.h_lineA,'linewidth',2);
0739
0740
0741 dat.n_wind=size(test_wind,1);
0742 if dat.n_wind
0743 for nw=1:dat.n_wind,
0744 dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),vA(3:4),'k--');
0745 set(dat.h_wind1A(nw),'linewidth',2);
0746 dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),vA(3:4),'k--');
0747 set(dat.h_wind2A(nw),'linewidth',2);
0748 end
0749 else
0750 dat.h_wind1A=[];
0751 dat.h_wind2A=[];
0752 end
0753
0754
0755 h=ylabel('\muV (ERP)');
0756 dat.h_time_ylabA=h;
0757 set(h,'fontsize',10,'fontunits','normalized');
0758
0759
0760 new_title=['Bin ' int2str(bin) ': ' dat.bindesc{bin}];
0761 title_max_char=43;
0762 if length(new_title)>title_max_char,
0763 new_title=new_title(1:title_max_char);
0764 end
0765 dat.h_time_title=title(new_title);
0766 set(dat.h_time_title,'fontsize',10,'fontunits','normalized');
0767 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0768 'dat=get(gcbf, ''userdata'');' ...
0769 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
0770 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
0771 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
0772 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
0773 'set(dat.fig_id,''userdata'',dat);' ...
0774 'gui_erp(''redraw topo'');' ...
0775 'drawnow;' ...
0776 'clear latpoint dattmp tmppos;' ...
0777 ];
0778 set(dat.h_timeA,'ButtonDownFcn',bdf_code);
0779 set(dat.h_showingA,'ButtonDownFcn',bdf_code);
0780
0781
0782
0783
0784
0785
0786 frm_col=[1 1 1]*.702;
0787 uipanel(dat.fig_id,...
0788 'Units','normalized', ...
0789 'Position',[ 0 0.175 .72 0.42 ],...
0790 'shadowcolor','k', ...
0791 'highlightcolor',frm_col, ...
0792 'foregroundcolor',frm_col, ...
0793 'backgroundcolor',frm_col);
0794
0795 dat.h_timeB=axes('position',[0.1 .25 .6 .33]);
0796 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
0797 stat_mx=max(max(dat.showingB(:,dat.start_pt:dat.end_pt)));
0798 stat_mn=min(min(dat.showingB(:,dat.start_pt:dat.end_pt)));
0799 stat_rng=stat_mx-stat_mn;
0800 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
0801 stat_plt_rng=round(stat_plt_rng*100)/100;
0802 plot([p.Results.GNDorGRP.time_pts(1) p.Results.GNDorGRP.time_pts(end)],[0 0],'k');
0803 hold on;
0804 dat.h_t0lineB=plot([0 0],stat_plt_rng,'k');
0805 set(dat.h_timeB,'ygrid','on');
0806 if ydir<0,
0807 set(dat.h_timeB,'ydir','reverse');
0808 end
0809 if size(dat.showingB,1)==1,
0810
0811 dat.h_showingB=plot(dat.times,dat.showingB);
0812 else
0813 dat.h_showingB=plot(dat.times,dat.showingB');
0814 end
0815 axis tight;
0816 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
0817 vB=axis;
0818 dat.h_lineB=plot([1 1]*plotted_times(mx_tpt),vB(3:4),'k');
0819 set(dat.h_lineB,'linewidth',2);
0820
0821
0822 if dat.n_wind
0823 for nw=1:dat.n_wind,
0824 dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),vB(3:4),'k--');
0825 set(dat.h_wind1B(nw),'linewidth',2);
0826 dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),vB(3:4),'k--');
0827 set(dat.h_wind2B(nw),'linewidth',2);
0828 end
0829 else
0830 dat.h_wind1B=[];
0831 dat.h_wind2B=[];
0832 end
0833
0834
0835 dat.h_crit1=[];
0836 dat.h_crit2=[];
0837 dat.h_alph1=[];
0838 dat.h_alph2=[];
0839 if ~isempty(critical_t) && ~isempty(test_wind),
0840 if strcmpi(p.Results.stat,'t'),
0841 if isempty(dat.alpha),
0842 watchit('You did not specify an alpha level via optional input argument ''alpha''. Alpha level will not be displayed.');
0843 else
0844 for nw=1:dat.n_wind,
0845 dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*critical_t(1),'r--');
0846 set(dat.h_crit1(nw),'linewidth',3);
0847 if nw==1,
0848 tm_rng=p.Results.GNDorGRP.time_pts(end)-p.Results.GNDorGRP.time_pts(1);
0849 if strcmpi(dat.mltplcmp_crct,'fdr')
0850 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
0851 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
0852 else
0853 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
0854 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
0855 end
0856 set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
0857 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
0858 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
0859 end
0860 end
0861 end
0862 if length(critical_t)>1,
0863 for nw=1:dat.n_wind,
0864 dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*critical_t(2),'r--');
0865 set(dat.h_crit2(nw),'linewidth',3);
0866 if nw==1,
0867 if strcmpi(dat.mltplcmp_crct,'fdr')
0868 dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
0869 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
0870 else
0871 dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
0872 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
0873 end
0874 set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
0875 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
0876 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
0877 end
0878 end
0879 end
0880 end
0881 end
0882
0883 h=xlabel('Time (msec)');
0884 set(h,'fontsize',10,'fontunits','normalized');
0885
0886
0887 if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)),
0888 h=ylabel('\muV (GFP)');
0889 elseif strcmpi(p.Results.stat,'t'),
0890 h=ylabel('t-score');
0891 else
0892 h=ylabel('\muV (StdEr)');
0893 end
0894 dat.h_time_ylabB=h;
0895 set(h,'fontsize',10,'fontunits','normalized');
0896
0897 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0898 'dat=get(gcbf, ''userdata'');' ...
0899 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
0900 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
0901 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
0902 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
0903 'set(dat.fig_id,''userdata'',dat);' ...
0904 'gui_erp(''redraw topo'');' ...
0905 'drawnow;' ...
0906 'clear latpoint dattmp tmppos;' ...
0907 ];
0908 set(dat.h_timeB,'ButtonDownFcn',bdf_code);
0909 set(dat.h_showingB,'ButtonDownFcn',bdf_code);
0910
0911
0912
0913
0914
0915
0916 uipanel(dat.fig_id,...
0917 'Units','normalized', ...
0918 'Position',[ 0.719 0.59 0.281 0.42 ],...
0919 'shadowcolor','k', ...
0920 'highlightcolor',frm_col, ...
0921 'foregroundcolor',frm_col, ...
0922 'backgroundcolor',frm_col);
0923
0924
0925 dat.h_topoA=axes('position',[0.705 .68 .31 .24],'box','off');
0926
0927 sig_chans=[];
0928 if ~isempty(test_wind) && ~isempty(critical_t),
0929
0930
0931 for nw=1:dat.n_wind,
0932 if (dat.times(plotted_pts(mx_tpt))>=test_wind(nw,1)) && (dat.times(plotted_pts(mx_tpt))<=test_wind(nw,2)),
0933 if ~strcmpi(dat.mltplcmp_crct,'fdr') && (length(critical_t)==1) && isnan(critical_t)
0934
0935 mx_tpt_in_ms=plotted_times(mx_tpt);
0936 mx_tpt_epoch_id=find(dat.times==mx_tpt_in_ms);
0937 use_test_id=find(dat.psbl_tests==p.Results.t_test);
0938 pval_tpt_id=find(dat.t_tests(use_test_id).used_tpt_ids==mx_tpt_epoch_id);
0939 if ~isempty(pval_tpt_id)
0940 sig_chans_temp=find(dat.t_tests(use_test_id).adj_pval(:,pval_tpt_id)<dat.t_tests(use_test_id).desired_alphaORq);
0941 sig_chans_temp=dat.t_tests(use_test_id).used_chan_ids(sig_chans_temp);
0942 n_showing_chans=length(dat.showing_chans);
0943 sig_chans=zeros(1,n_showing_chans);
0944 for a=1:n_showing_chans,
0945 if ismember(dat.showing_chans(a),sig_chans_temp)
0946 sig_chans(a)=1;
0947 end
0948 end
0949 sig_chans=find(sig_chans);
0950 else
0951 sig_chans=[];
0952 end
0953 else
0954 if length(critical_t)==2,
0955
0956
0957 if isnan(critical_t(2))
0958 sig_chans=[];
0959 else
0960 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>max(critical_t));
0961 end
0962 if ~isnan(critical_t(1))
0963 sig_chans=[sig_chans; find(dat.showing_t(:,plotted_pts(mx_tpt))<min(critical_t))];
0964 end
0965 else
0966 if isnan(critical_t)
0967 sig_chans=[];
0968 elseif critical_t>0,
0969 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>critical_t);
0970 else
0971 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))<critical_t);
0972 end
0973 end
0974 end
0975 break;
0976 end
0977 end
0978 end
0979 cbar_title_fontsize=14;
0980 if size(dat.showingA,1)<=2,
0981
0982 topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0983 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
0984 cbar_title='Not Applicable';
0985 cbar_title_fontsize=10;
0986 else
0987 topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0988 'maplimits',[-1 1]*dat.absmxA,'emarker2',{sig_chans,'o',[1 1 1],4});
0989 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
0990 cbar_title='\muV';
0991 end
0992
0993
0994
0995 dat.h_cbarA=axes('position',[0.76 .945 .2 .015]);
0996 cbar(dat.h_cbarA);
0997 absmx=round(dat.absmxA*100)/100;
0998 set(gca,'xticklabel',[-absmx 0 absmx]);
0999 h_cbar_title=title(cbar_title);
1000 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1001
1002
1003
1004
1005 uicontrol(dat.fig_id,...
1006 'Units','normalized', ...
1007 'Position',[ 0.905 0.62 0.07 0.04 ],...
1008 'String','msec',...
1009 'fontsize',14, ...
1010 'fontunits','normalized', ...
1011 'Style','text');
1012 dat.h_topo_time=uicontrol(dat.fig_id,...
1013 'CallBack','gui_erp(''time jump'');',...
1014 'Units','normalized', ...
1015 'Position',[ 0.805 0.62 0.1 0.05 ], ...
1016 'String',num2str(plotted_times(mx_tpt)), ...
1017 'Style','edit', ...
1018 'Enable','on', ...
1019 'ToolTipString','Time point to visualize topographicaly.', ...
1020 'fontsize',14, ...
1021 'fontunits','normalized', ...
1022 'horizontalalignment','center', ...
1023 'BackGroundColor','w', ...
1024 'Tag','topo_time');
1025
1026
1027
1028
1029
1030
1031
1032
1033 uipanel(dat.fig_id,...
1034 'Units','normalized', ...
1035 'Position',[ 0.719 0.175 0.281 0.42 ],...
1036 'shadowcolor','k', ...
1037 'highlightcolor',frm_col, ...
1038 'foregroundcolor',frm_col, ...
1039 'backgroundcolor',frm_col);
1040
1041
1042 dat.h_topoB=axes('position',[0.705 .27 .31 .24],'box','off');
1043
1044 cbar_title_fontsize=14;
1045 if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
1046 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
1047 'style','blank','plain_blank',1);
1048 cbar_title='Not Applicable';
1049 cbar_title_fontsize=10;
1050 else
1051 if size(dat.showingB,1)<=2,
1052
1053 topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1054 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
1055 cbar_title='Not Applicable';
1056 cbar_title_fontsize=10;
1057 else
1058 topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1059 'maplimits',[-1 1]*dat.absmxB,'emarker2',{sig_chans,'o',[1 1 1],4});
1060 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
1061 if strcmpi(p.Results.stat,'t'),
1062 cbar_title='t-score';
1063 else
1064 cbar_title='\muV';
1065 end
1066 end
1067 end
1068
1069
1070 dat.h_cbarB=axes('position',[0.76 .535 .2 .015]);
1071 cbar(dat.h_cbarB);
1072 absmx=round(dat.absmxB*100)/100;
1073 set(gca,'xticklabel',[-absmx 0 absmx]);
1074 h_cbar_title=title(cbar_title);
1075 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1076
1077
1078 dat.h_back1=uicontrol(dat.fig_id,...
1079 'CallBack','gui_erp(''back one'');',...
1080 'Units','normalized', ...
1081 'Position',[ 0.80 0.232 0.055 0.04 ],...
1082 'String','<',...
1083 'fontsize',14, ...
1084 'fontunits','normalized', ...
1085 'Tag','back1', ...
1086 'ToolTipString','Show topography at preceding time point.', ...
1087 'Style','pushbutton');
1088
1089
1090 dat.h_forward1=uicontrol(dat.fig_id,...
1091 'CallBack','gui_erp(''forward one'');',...
1092 'Units','normalized', ...
1093 'Position',[ 0.865 0.232 0.055 0.04 ],...
1094 'String','>', ...
1095 'fontsize',14, ...
1096 'fontunits','normalized', ...
1097 'Tag','forward1', ...
1098 'ToolTipString','Show topography at subsequent time point.', ...
1099 'Style','pushbutton');
1100
1101
1102 dat.h_back=uicontrol(dat.fig_id,...
1103 'CallBack','gui_erp(''back'');',...
1104 'Units','normalized', ...
1105 'Position',[ 0.735 0.232 0.055 0.04 ],...
1106 'String','<<',...
1107 'fontsize',14, ...
1108 'fontunits','normalized', ...
1109 'Tag','back', ...
1110 'interruptible','on', ...
1111 'ToolTipString','Animate topography going backwards in time.', ...
1112 'Style','pushbutton');
1113
1114
1115 dat.h_forward=uicontrol(dat.fig_id,...
1116 'CallBack','gui_erp(''forward'');',...
1117 'Units','normalized', ...
1118 'Position',[ 0.93 0.232 0.055 0.04 ],...
1119 'String','>>',...
1120 'fontsize',14, ...
1121 'fontunits','normalized', ...
1122 'Tag','back', ...
1123 'interruptible','on', ...
1124 'ToolTipString','Animate topography going forwards in time.', ...
1125 'Style','pushbutton');
1126
1127
1128 dat.h_stop=uicontrol(dat.fig_id,...
1129 'CallBack','dat=get(gcbf,''userdata''); dat.interrupt=1; set(dat.fig_id,''userdata'',dat);',...
1130 'Units','normalized', ...
1131 'Position',[ 0.745 0.179 0.23 0.05 ],...
1132 'String','Stop Animation',...
1133 'fontsize',14, ...
1134 'fontunits','normalized', ...
1135 'Tag','stop', ...
1136 'enable','off', ...
1137 'ToolTipString','Stop topography animation.', ...
1138 'Style','pushbutton');
1139
1140
1141
1142
1143
1144
1145
1146
1147 uipanel(dat.fig_id,...
1148 'Units','normalized', ...
1149 'Position',[ 0 0 1 0.178 ],...
1150 'shadowcolor','k', ...
1151 'highlightcolor',frm_col, ...
1152 'foregroundcolor',frm_col, ...
1153 'backgroundcolor',frm_col);
1154
1155
1156
1157 bdesc_str=cell(1,n_bin);
1158 for a=1:n_bin,
1159 bdesc_str{a}=sprintf('Bin %d: %s',a,dat.bindesc{a});
1160 end
1161
1162 uicontrol(dat.fig_id,...
1163 'Units','normalized', ...
1164 'Position',[ 0.01 0.115 0.2 0.05 ],...
1165 'String','Current Bin',...
1166 'fontsize',12, ...
1167 'ToolTipString','Bin to plot in Time x ERP/t-score axis.', ...
1168 'Style','text');
1169
1170 dat.h_bin=uicontrol(dat.fig_id,...
1171 'CallBack','gui_erp(''change bin'');',...
1172 'Units','normalized', ...
1173 'Position',[ 0.01 0.08 0.24 0.05 ],...
1174 'fontsize',12, ...
1175 'String',bdesc_str, ...
1176 'Value',bin, ...
1177 'Style','popup', ...
1178 'ToolTipString','Bin to plot in Time x ERP/t-score axis.', ...
1179 'tag','bin');
1180
1181
1182
1183 ttest_str=cell(1,n_psbl_tests+1);
1184 for a=1:n_psbl_tests,
1185 ttest_str{a}=sprintf('Test %d: Bin %d, Times ',dat.psbl_tests(a),dat.t_tests(a).bin);
1186 n_ttst_wind=size(dat.t_tests(a).time_wind,1);
1187 for b=1:n_ttst_wind,
1188 ttest_str{a}=[ttest_str{a} int2str(dat.t_tests(a).time_wind(b,1)) '-' int2str(dat.t_tests(a).time_wind(b,2)) ','];
1189 end
1190 if length(dat.t_tests(a).crit_t)==2,
1191 ttest_str{a}=[ttest_str{a} ' Two-Tailed,'];
1192 elseif dat.t_tests(a).crit_t<0,
1193 ttest_str{a}=[ttest_str{a} ' Lower-Tailed,'];
1194 else
1195 ttest_str{a}=[ttest_str{a} ' Upper-Tailed,'];
1196 end
1197
1198 if isnan(dat.t_tests(a).estimated_alpha)
1199 ttest_str{a}=[ttest_str{a} sprintf(' q=%.4f',dat.t_tests(a).desired_alphaORq)];
1200 ttest_str{a}=[ttest_str{a} sprintf(', method=%s',dat.t_tests(a).mult_comp_method)];
1201 else
1202 ttest_str{a}=[ttest_str{a} sprintf(' alpha=%.4f',dat.t_tests(a).estimated_alpha)];
1203 end
1204
1205 if dat.t_tests(a).null_mean,
1206 ttest_str{a}=[ttest_str{a} sprintf(', Null Mean=%.4f',dat.t_tests(a).null_mean)];
1207 end
1208 end
1209 ttest_str{n_psbl_tests+1}='None/Manual';
1210
1211
1212 uicontrol(dat.fig_id,...
1213 'Units','normalized', ...
1214 'Position',[ 0.275 0.115 0.2 0.05 ],...
1215 'String','Current Test Result',...
1216 'fontsize',12, ...
1217 'ToolTipString','Set of t-test results to visualize.', ...
1218 'Style','text');
1219
1220 dat.h_ptest=uicontrol(dat.fig_id,...
1221 'CallBack','gui_erp(''change test'');',...
1222 'Units','normalized', ...
1223 'Position',[ 0.26 0.075 0.24 0.055 ],...
1224 'fontsize',12, ...
1225 'String',ttest_str, ...
1226 'Value',crnt_ttest, ...
1227 'Style','popup', ...
1228 'ToolTipString','Set of t-test results to visualize.', ...
1229 'tag','bin');
1230
1231
1232
1233 uicontrol(dat.fig_id,...
1234 'Units','normalized', ...
1235 'Position',[ 0.505 0.115 0.26 0.05 ],...
1236 'String','Test Window(s) [Min Max]:',...
1237 'fontsize',12, ...
1238 'Style','text');
1239
1240 wind_edges=[];
1241 for nw=1:dat.n_wind,
1242 if nw==dat.n_wind,
1243 wind_edges=[wind_edges num2str(test_wind(nw,:))];
1244 else
1245 wind_edges=[wind_edges num2str(test_wind(nw,:)) '; '];
1246 end
1247 end
1248 dat.h_testwind=uicontrol(dat.fig_id,...
1249 'CallBack','gui_erp(''update dashed lines'');',...
1250 'Units','normalized', ...
1251 'fontsize',12, ...
1252 'BackGroundColor','w', ...
1253 'Position',[ 0.525 0.095 0.22 0.04 ],...
1254 'String',wind_edges, ...
1255 'Style','edit', ...
1256 'ToolTipString','Miniumum and maximum time of time window in which hypothesis tests were done.', ...
1257 'tag','timerange');
1258
1259
1260
1261
1262 uicontrol(dat.fig_id,...
1263 'Units','normalized', ...
1264 'Position',[ 0.76 0.115 0.23 0.05 ],...
1265 'String','Critical t-score(s)',...
1266 'fontsize',12, ...
1267 'Style','text');
1268
1269 dat.h_critval=uicontrol(dat.fig_id,...
1270 'CallBack','gui_erp(''update critical t'');',...
1271 'Units','normalized', ...
1272 'fontsize',12, ...
1273 'BackGroundColor','w', ...
1274 'Position',[ 0.79 0.09 0.16 0.045 ],...
1275 'String',num2str(critical_t), ...
1276 'Style','edit', ...
1277 'ToolTipString','Critical t-score(s) for reliable deviation from 0 voltage.', ...
1278 'tag','timerange');
1279
1280
1281 stats={'t-score of ERPs','standard error of ERPs','global field power of ERPs'};
1282
1283 uicontrol(dat.fig_id,...
1284 'Units','normalized', ...
1285 'Position',[ 0.01 0.183 0.09 0.03 ],...
1286 'String','Statistic:',...
1287 'fontsize',12, ...
1288 'ToolTipString','Select what to plot in secondary waveform axis: ERP t-scores, standard error of the mean, or global field power.', ...
1289 'Style','text');
1290
1291 if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
1292
1293
1294 ini_val=3;
1295 elseif strcmpi(p.Results.stat,'t'),
1296 ini_val=1;
1297 elseif strcmpi(p.Results.stat,'stder'),
1298 ini_val=2;
1299 else
1300 error('Unrecognized value of input argument ''stat''.');
1301 end
1302 dat.h_stat=uicontrol(dat.fig_id,...
1303 'CallBack','gui_erp(''change stat'');',...
1304 'Units','normalized', ...
1305 'Position',[ 0.095 0.165 0.16 0.05 ],...
1306 'fontsize',12, ...
1307 'value',ini_val, ...
1308 'String',stats, ...
1309 'Style','popup', ...
1310 'ToolTipString','Plot ERP t-scores or standard error of the mean in secondary axis?', ...
1311 'tag','stat');
1312
1313
1314
1315 uicontrol(dat.fig_id,...
1316 'Units','normalized', ...
1317 'Position',[ 0.01 0.035 0.24 0.05 ],...
1318 'String','Time Range [Min Max]',...
1319 'fontsize',12, ...
1320 'Style','text');
1321
1322 dat.h_timerange=uicontrol(dat.fig_id,...
1323 'CallBack','gui_erp(''new time limits'');',...
1324 'Units','normalized', ...
1325 'fontsize',12, ...
1326 'BackGroundColor','w', ...
1327 'Position',[ 0.06 0.013 0.11 0.045 ],...
1328 'String',num2str(dat.plt_times), ...
1329 'Style','edit', ...
1330 'ToolTipString','Miniumum and maximum time on Time x ERP axis.', ...
1331 'tag','timerange');
1332
1333
1334
1335 uicontrol(dat.fig_id,...
1336 'Units','normalized', ...
1337 'Position',[ 0.26 0.035 0.26 0.05 ],...
1338 'String','ERP Range [Min Max]',...
1339 'HorizontalAlignment','left', ...
1340 'fontsize',12, ...
1341 'Style','text');
1342
1343 dat.h_statrangeA=uicontrol(dat.fig_id,...
1344 'CallBack','gui_erp(''new statistic limitsA'');',...
1345 'Units','normalized', ...
1346 'fontsize',12, ...
1347 'BackGroundColor','w', ...
1348 'Position',[ 0.28 0.013 0.16 0.045 ],...
1349 'String',num2str(round(vA(3:4)*100)/100), ...
1350 'ToolTipString','Miniumum and maximum voltage on Time x ERP axis.', ...
1351 'Style','edit', ...
1352 'tag','statrange');
1353
1354
1355
1356 uicontrol(dat.fig_id,...
1357 'Units','normalized', ...
1358 'Position',[ 0.50 0.035 0.26 0.05 ],...
1359 'String','t/StdErr Range [Min Max]',...
1360 'HorizontalAlignment','left', ...
1361 'fontsize',12, ...
1362 'Style','text');
1363
1364 dat.h_statrangeB=uicontrol(dat.fig_id,...
1365 'CallBack','gui_erp(''new statistic limitsB'');',...
1366 'Units','normalized', ...
1367 'fontsize',12, ...
1368 'BackGroundColor','w', ...
1369 'Position',[ 0.54 0.013 0.16 0.045 ],...
1370 'String',num2str(round(vB(3:4)*100)/100), ...
1371 'ToolTipString','Miniumum and maximum t-scores/voltage on Time x t-Scores/Standard Error/GFP axis.', ...
1372 'Style','edit', ...
1373 'tag','statrange');
1374
1375
1376 uicontrol(dat.fig_id,...
1377 'CallBack','close(gcbf);',...
1378 'Units','normalized', ...
1379 'Position',[ 0.75 0.012 0.11 0.05 ],...
1380 'String','Close',...
1381 'fontsize',12, ...
1382 'Tag','close', ...
1383 'backgroundcolor','m', ...
1384 'ToolTipString','Close GUI', ...
1385 'Style','pushbutton');
1386
1387 dat.help_msg=sprintf(['Hold mouse cursor over a GUI control for an explanation of what it does.\n\n', ...
1388 'Time x waveform axis visualizes ERPs, t-score of ERPs, standard error of ERPs, or ERP global field power simultaneously at multiple electrodes. ' ...
1389 'Each colored line corresponds to a different electrode.\n\nClick on Time x uV/t-score/stderr/GFP axis to visualize the scalp topography\n', ...
1390 'at that point in time.\n\nClick on electrodes in scalp topography to see electrode name.\n\n', ...
1391 'This GUI was produced by gui_erp.m']);
1392
1393
1394 uicontrol(dat.fig_id,...
1395 'CallBack','dat=get(gcbf,''userdata''); helpdlg(dat.help_msg,''ERP GUI Help'');', ...
1396 'Units','normalized', ...
1397 'Position',[ 0.87 0.01 0.11 0.05 ],...
1398 'String','Help',...
1399 'fontsize',12, ...
1400 'Tag','help', ...
1401 'ToolTipString','Click for help', ...
1402 'Style','pushbutton');
1403 dat.interrupt=1;
1404 set(dat.fig_id,'userdata',dat);
1405 elseif strcmpi(cmnd_str,'time jump'),
1406 new_tpt=find_tpt(str2num(get(dat.h_topo_time,'string')), ...
1407 dat.times);
1408 if new_tpt<dat.start_pt,
1409 errordlg('That time is too early.');
1410 elseif new_tpt>dat.end_pt,
1411 errordlg('That time is too late.');
1412 else
1413 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1414 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1415 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1416 set(dat.fig_id,'userdata',dat);
1417 redraw_topos(dat,0);
1418 drawnow;
1419 end
1420 elseif strcmpi(cmnd_str,'back one'),
1421 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1422 dat.times);
1423 new_tpt=current_tpt-1;
1424 if new_tpt<dat.start_pt,
1425 errordlg('Can''t go back any further.');
1426 else
1427 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1428 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1429 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1430 set(dat.fig_id,'userdata',dat);
1431 redraw_topos(dat,0);
1432 drawnow;
1433 end
1434 elseif strcmpi(cmnd_str,'forward one'),
1435 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1436 dat.times);
1437 new_tpt=current_tpt+1;
1438 if new_tpt>dat.end_pt,
1439 errordlg('Can''t go forward any further.');
1440 else
1441 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1442 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1443 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1444 set(dat.fig_id,'userdata',dat);
1445 redraw_topos(dat,0);
1446 drawnow;
1447 end
1448 elseif strcmpi(cmnd_str,'back'),
1449 interrupt=0;
1450 dat.interrupt=0;
1451 set(dat.h_stop,'enable','on');
1452 set(dat.h_forward,'enable','off');
1453 set(dat.h_back,'enable','off');
1454 set(dat.h_forward1,'enable','off');
1455 set(dat.h_back1,'enable','off');
1456 set(dat.fig_id,'userdata',dat);
1457 drawnow;
1458 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1459 dat.times);
1460 new_tpt=current_tpt-1;
1461 loop_ct=0;
1462 while (new_tpt>=dat.start_pt) && (interrupt~=1),
1463 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1464 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1465 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1466 drawnow('update');
1467 redraw_topos(dat,0);
1468 drawnow;
1469 new_tpt=new_tpt-1;
1470 loop_ct=loop_ct+1;
1471 if loop_ct==5,
1472 loop_ct=0;
1473 new_tmp=get(dat.fig_id,'userdata');
1474 interrupt=new_tmp.interrupt;
1475 end
1476 end
1477 drawnow;
1478 dat.interrupt=0;
1479 new_tpt=new_tpt+1;
1480 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1481 set(dat.h_stop,'enable','off');
1482 set(dat.h_forward,'enable','on');
1483 set(dat.h_back,'enable','on');
1484 set(dat.h_forward1,'enable','on');
1485 set(dat.h_back1,'enable','on');
1486 set(dat.fig_id,'userdata',dat);
1487 elseif strcmpi(cmnd_str,'forward'),
1488 interrupt=0;
1489 dat.interrupt=0;
1490 set(dat.h_stop,'enable','on');
1491 set(dat.h_forward,'enable','off');
1492 set(dat.h_back,'enable','off');
1493 set(dat.h_forward1,'enable','off');
1494 set(dat.h_back1,'enable','off');
1495 set(dat.fig_id,'userdata',dat);
1496 drawnow;
1497 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1498 dat.times);
1499 new_tpt=current_tpt+1;
1500 loop_ct=0;
1501 while (new_tpt<=dat.end_pt) && (interrupt~=1),
1502 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1503 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1504 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1505 drawnow('update');
1506 redraw_topos(dat,0);
1507 drawnow;
1508 new_tpt=new_tpt+1;
1509 loop_ct=loop_ct+1;
1510 if loop_ct==5,
1511 loop_ct=0;
1512 new_tmp=get(dat.fig_id,'userdata');
1513 interrupt=new_tmp.interrupt;
1514 end
1515 end
1516 drawnow;
1517 dat.interrupt=0;
1518 new_tpt=new_tpt-1;
1519 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1520 set(dat.h_stop,'enable','off');
1521 set(dat.h_forward,'enable','on');
1522 set(dat.h_back,'enable','on');
1523 set(dat.h_forward1,'enable','on');
1524 set(dat.h_back1,'enable','on');
1525 set(dat.fig_id,'userdata',dat);
1526 elseif strcmpi(cmnd_str,'change stat'),
1527 stat=get(dat.h_stat,'value');
1528 current_bin=get(dat.h_bin,'value');
1529 if (stat~=3),
1530
1531 if isinf(dat.t_scores(1,1,current_bin)) || isnan(dat.t_scores(1,1,current_bin))
1532 stat=3;
1533 set(dat.h_stat,'value',stat);
1534 if (stat==2)
1535 warndlg('Only one participant contributed to this bin. Thus the grand average standard error cannot be esimated.','gui_erp Warning');
1536 else
1537 warndlg('Only one participant contributed to this bin. Thus the grand average t-scores cannot be derived.','gui_erp Warning');
1538 end
1539 end
1540 end
1541
1542 if (stat==1),
1543
1544 if ~isempty(dat.h_crit1),
1545 delete(dat.h_crit1);
1546 end
1547 if ~isempty(dat.h_crit2),
1548 delete(dat.h_crit2);
1549 end
1550 dat.h_crit1=[];
1551 dat.h_crit2=[];
1552
1553 if ~isempty(dat.h_alph1),
1554 delete(dat.h_alph1);
1555 end
1556 if ~isempty(dat.h_alph2),
1557 delete(dat.h_alph2);
1558 end
1559 dat.h_alph1=[];
1560 dat.h_alph2=[];
1561 end
1562
1563
1564 draw_waveforms(dat,0);
1565 gui_erp('update dashed lines');
1566 elseif strcmpi(cmnd_str,'change bin'),
1567 new_bin=get(dat.h_bin,'value');
1568 crnt_ttest_id=get(dat.h_ptest,'value');
1569 n_t_tests=length(dat.t_tests);
1570 if (crnt_ttest_id==(n_t_tests+1)) || (dat.t_tests(crnt_ttest_id).bin~=new_bin),
1571
1572
1573
1574
1575
1576 crnt_ttest_id=n_t_tests+1;
1577 for a=1:n_t_tests,
1578 if dat.t_tests(a).bin==new_bin;
1579 crnt_ttest_id=a;
1580 break;
1581 end
1582 end
1583 set(dat.h_ptest,'value',crnt_ttest_id);
1584 dat=update_test(dat);
1585 end
1586 draw_waveforms(dat,1);
1587 gui_erp('update dashed lines');
1588 elseif strcmpi(cmnd_str,'new time limits'),
1589
1590 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1591 tme_lim=str2num(get(dat.h_timerange,'string'));
1592 if length(tme_lim)~=2,
1593 errordlg('Enter exactly two values for time range (desired Min and Max values).','gui_erp Error');
1594 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1595 elseif tme_lim(2)<tme_lim(1),
1596 errordlg('The second time range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1597 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1598 elseif (tme_lim(1)<dat.times(1)) || (tme_lim(2)>dat.times(end))
1599 errordlg(sprintf('Time range values must be between %d and %d msec.',dat.times(1),dat.times(end)),'gui_erp Error');
1600 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1601 else
1602
1603 set(dat.h_timeA,'xlim',tme_lim);
1604 set(dat.h_timeB,'xlim',tme_lim);
1605 dat.start_pt=find_tpt(tme_lim(1),dat.times);
1606 dat.end_pt=find_tpt(tme_lim(2),dat.times);
1607
1608
1609 dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
1610 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1611 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1612 dat.times);
1613 if (current_tpt>dat.end_pt) || (current_tpt<dat.start_pt)
1614
1615
1616
1617 [dummy, mx_tpt]=max(max(abs(dat.showing_t(:,dat.start_pt:dat.end_pt))));
1618 showing_pts=dat.start_pt:dat.end_pt;
1619 set(dat.h_lineA,'xdata',[1 1]*dat.times(showing_pts(mx_tpt)));
1620 set(dat.h_lineB,'xdata',[1 1]*dat.times(showing_pts(mx_tpt)));
1621
1622 set(dat.h_topo_time,'string',num2str(dat.times(showing_pts(mx_tpt))));
1623 end
1624
1625 redraw_topos(dat,1);
1626 set(dat.fig_id,'userdata',dat);
1627 end
1628 elseif strcmpi(cmnd_str,'new statistic limitsA'),
1629
1630 plotted_limits=get(dat.h_timeA,'ylim');
1631 new_lim=str2num(get(dat.h_statrangeA,'string'));
1632 if length(new_lim)~=2,
1633 errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_erp Error');
1634 set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1635 elseif new_lim(2)<new_lim(1),
1636 errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1637 set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1638 else
1639
1640 set(dat.h_timeA,'ylim',new_lim);
1641 set(dat.h_t0lineA,'YData',new_lim);
1642 set(dat.h_lineA,'YData',new_lim);
1643
1644
1645 if ~isempty(dat.h_wind1A)
1646 set(dat.h_wind1A,'YData',new_lim);
1647 set(dat.h_wind2A,'YData',new_lim);
1648 end
1649 end
1650 elseif strcmpi(cmnd_str,'new statistic limitsB'),
1651
1652 plotted_limits=get(dat.h_timeB,'ylim');
1653 new_lim=str2num(get(dat.h_statrangeB,'string'));
1654 if length(new_lim)~=2,
1655 errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_erp Error');
1656 set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1657 elseif new_lim(2)<new_lim(1),
1658 errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1659 set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1660 else
1661
1662 set(dat.h_timeB,'ylim',new_lim);
1663 set(dat.h_t0lineB,'YData',new_lim);
1664 set(dat.h_lineB,'YData',new_lim);
1665
1666
1667 if ~isempty(dat.h_wind1B)
1668 set(dat.h_wind1B,'YData',new_lim);
1669 set(dat.h_wind2B,'YData',new_lim);
1670 end
1671 end
1672 elseif strcmpi(cmnd_str,'redraw topo'),
1673 redraw_topos(dat,1);
1674 elseif strcmpi(cmnd_str,'update dashed lines'),
1675 test_wind=str2num(get(dat.h_testwind,'string'));
1676
1677 if (size(test_wind,2)>2) || (isempty(test_wind) && ~isempty(get(dat.h_testwind,'string')))
1678 errordlg('Enter pairs of values for time window range (desired Min and Max values) or leave box blank. Separate multiple pairs with semicolons.', ...
1679 'gui_erp Error');
1680 elseif length(dat.critical_t)>2,
1681 errordlg('Enter one (for one-tailed test) or two (for two-tailed test) value(s) for critical t-scores or leave box blank.', ...
1682 'gui_erp Error');
1683 else
1684 if isempty(test_wind),
1685 test_wind=[NaN NaN];
1686 end
1687
1688
1689 if ~isempty(dat.h_crit1),
1690 delete(dat.h_crit1);
1691 end
1692 if ~isempty(dat.h_crit2),
1693 delete(dat.h_crit2);
1694 end
1695 if ~isempty(dat.h_alph1),
1696 delete(dat.h_alph1);
1697 end
1698 if ~isempty(dat.h_alph2),
1699 delete(dat.h_alph2);
1700 end
1701 if ~isempty(dat.h_wind1A),
1702 delete(dat.h_wind1A);
1703 end
1704 if ~isempty(dat.h_wind2A),
1705 delete(dat.h_wind2A);
1706 end
1707 if ~isempty(dat.h_wind1B),
1708 delete(dat.h_wind1B);
1709 end
1710 if ~isempty(dat.h_wind2B),
1711 delete(dat.h_wind2B);
1712 end
1713 dat.h_wind1A=[];
1714 dat.h_wind2A=[];
1715 dat.h_wind1B=[];
1716 dat.h_wind2B=[];
1717 dat.h_crit1=[];
1718 dat.h_crit2=[];
1719 dat.h_alph1=[];
1720 dat.h_alph2=[];
1721 dat.n_wind=size(test_wind,1);
1722
1723 if ~sum(isnan(test_wind))
1724 y_rngA=get(dat.h_timeA,'YLim');
1725 y_rngB=get(dat.h_timeB,'YLim');
1726
1727 axes(dat.h_timeA);
1728 for nw=1:dat.n_wind,
1729 dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),y_rngA,'k--');
1730 set(dat.h_wind1A(nw),'linewidth',2);
1731 dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),y_rngA,'k--');
1732 set(dat.h_wind2A(nw),'linewidth',2);
1733 end
1734
1735 axes(dat.h_timeB);
1736 for nw=1:dat.n_wind,
1737 dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),y_rngB,'k--');
1738 set(dat.h_wind1B(nw),'linewidth',2);
1739 dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),y_rngB,'k--');
1740 set(dat.h_wind2B(nw),'linewidth',2);
1741 end
1742
1743
1744 stat=get(dat.h_stat,'value');
1745
1746
1747 if ~sum(isnan(dat.critical_t)) && (stat==1) && ~isempty(dat.critical_t)
1748 for nw=1:dat.n_wind,
1749 dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(1),'r--');
1750 set(dat.h_crit1(nw),'linewidth',3);
1751 if nw==1,
1752
1753 tm_rng=dat.times(end)-dat.times(1);
1754 if strcmpi(dat.mltplcmp_crct,'fdr')
1755 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1756 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1757 else
1758 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1759 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1760 end
1761 set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
1762 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1763 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1764 end
1765 if length(dat.critical_t)>1,
1766 dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(2),'r--');
1767 set(dat.h_crit2(nw),'linewidth',3);
1768 if nw==1,
1769
1770 if strcmpi(dat.mltplcmp_crct,'fdr')
1771 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1772 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1773 else
1774 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1775 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1776 end
1777 set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
1778 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1779 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1780 end
1781 end
1782 end
1783 end
1784 end
1785 set(dat.fig_id,'userdata',dat);
1786 redraw_topos(dat,1);
1787 end
1788 elseif strcmpi(cmnd_str,'update critical t'),
1789 critical_t=str2num(get(dat.h_critval,'string'));
1790 if ~isequal(sort(critical_t),sort(dat.critical_t)),
1791 new_alpha=[];
1792 while isempty(new_alpha),
1793 new_alpha=inputdlg({'Enter alpha level for new critical t-score(s)'}, ...
1794 'Set New Alpha Level',1,{num2str(dat.alpha)});
1795 new_alpha=str2num(new_alpha{1});
1796 if isempty(new_alpha),
1797 errrodlg('You must enter a numeric value for the new alpha level','gui_erp Error');
1798 end
1799 end
1800 dat.alpha=new_alpha;
1801 dat.critical_t=critical_t;
1802 end
1803 set(dat.fig_id,'userdata',dat);
1804 gui_erp('update dashed lines');
1805 elseif strcmpi(cmnd_str,'change test'),
1806 [dat, redraw_wform]=update_test(dat);
1807 if redraw_wform,
1808 draw_waveforms(dat,1);
1809 end
1810 gui_erp('update dashed lines');
1811 else
1812 errordlg(sprintf('Command "%s" not recognized by gui_erp.m',cmnd_str), ...
1813 'gui_erp Error');
1814 end
1815
1816
1817 function draw_waveforms(dat,redrawA)
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827 new_bin=get(dat.h_bin,'value');
1828 stat=get(dat.h_stat,'value');
1829 crnt_ttest_id=get(dat.h_ptest,'value');
1830 n_t_tests=length(dat.t_tests);
1831 if crnt_ttest_id==n_t_tests+1,
1832
1833 dat.showing_chans=dat.loaded_chans;
1834 else
1835 dat.showing_chans=intersect(dat.t_tests(crnt_ttest_id).used_chan_ids, ...
1836 dat.loaded_chans);
1837 end
1838
1839
1840 axes(dat.h_timeB);
1841 delete(dat.h_showingB);
1842 delete(dat.h_lineB);
1843 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1844
1845 if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1846
1847 dat.showing_t=squeeze( (dat.erp(dat.showing_chans,:,new_bin)- ...
1848 dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1849 else
1850 dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1851 end
1852
1853 if (stat==1),
1854 dat.showingB=dat.showing_t;
1855 cbar_title='t-score';
1856 ylab='t-score';
1857 elseif (stat==2),
1858 dat.showingB=squeeze(dat.stder(dat.showing_chans,:,new_bin));
1859 cbar_title='\muV';
1860 ylab='\muV (StdEr)';
1861 elseif (stat==3),
1862 dat.showingB=dat.gfp(:,new_bin)';
1863 cbar_title='\muV';
1864 ylab='\muV (GFP)';
1865 end
1866 if size(dat.showingB,1)==1,
1867
1868 dat.h_showingB=plot(dat.times,dat.showingB);
1869 cbar_title='Not Applicable';
1870 cbar_title_fontsize=10;
1871 else
1872 dat.h_showingB=plot(dat.times,dat.showingB');
1873 cbar_title_fontsize=14;
1874 end
1875 set(dat.h_time_ylabB,'string',ylab);
1876
1877 stat_mx=max(max(dat.showingB));
1878 stat_mn=min(min(dat.showingB));
1879
1880 if isnan(stat_mx) || isnan(stat_mn)
1881 error('Bin %d does not appear to have any data in it.',new_bin);
1882 end
1883 stat_rng=stat_mx-stat_mn;
1884 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1885 stat_plt_rng=round(stat_plt_rng*100)/100;
1886 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
1887 set(dat.h_statrangeB,'string',num2str(stat_plt_rng));
1888 set(dat.h_t0lineB,'YData',stat_plt_rng);
1889 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1890 dat.times);
1891 h_lineB=plot([1 1]*dat.times(current_tpt),stat_plt_rng,'k');
1892 set(h_lineB,'linewidth',2);
1893 dat.h_lineB=h_lineB;
1894
1895 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1896 'dat=get(gcbf, ''userdata'');' ...
1897 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
1898 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
1899 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
1900 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
1901 'set(dat.fig_id,''userdata'',dat);' ...
1902 'gui_erp(''redraw topo'');' ...
1903 'drawnow;' ...
1904 'clear latpoint dattmp tmppos;' ...
1905 ];
1906 set(dat.h_showingB,'ButtonDownFcn',bdf_code);
1907 set(dat.h_timeB,'ButtonDownFcn',bdf_code);
1908
1909
1910 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1911 axes(dat.h_cbarB);
1912 cla;
1913 cbar(dat.h_cbarB);
1914 absmx=round(dat.absmxB*100)/100;
1915 set(gca,'xticklabel',[-absmx 0 absmx]);
1916 h_cbar_title=title(cbar_title);
1917 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1918
1919 if redrawA,
1920
1921 new_title=['Bin ' int2str(new_bin) ': ' dat.bindesc{new_bin}];
1922 title_max_char=43;
1923 if length(new_title)>title_max_char,
1924 new_title=new_title(1:title_max_char);
1925 end
1926 set(dat.h_time_title,'string',new_title);
1927
1928
1929
1930 axes(dat.h_timeA);
1931 delete(dat.h_showingA);
1932 delete(dat.h_lineA);
1933 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1934
1935 if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1936
1937 dat.showing_t=squeeze( (dat.erp(dat.showing_chans,:,new_bin)- ...
1938 dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1939 else
1940 dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1941 end
1942
1943 dat.showingA=squeeze(dat.erp(dat.showing_chans,:,new_bin));
1944 cbar_title='\muV';
1945 ylab='\muV (ERP)';
1946 if size(dat.showingA,1)==1,
1947
1948 dat.h_showingA=plot(dat.times,dat.showingA);
1949 cbar_title='Not Applicable';
1950 cbar_title_fontsize=10;
1951 else
1952 dat.h_showingA=plot(dat.times,dat.showingA');
1953 end
1954 set(dat.h_time_ylabA,'string',ylab);
1955
1956 stat_mx=max(max(dat.showingA));
1957 stat_mn=min(min(dat.showingA));
1958 stat_rng=stat_mx-stat_mn;
1959 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1960 stat_plt_rng=round(stat_plt_rng*100)/100;
1961 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
1962 set(dat.h_statrangeA,'string',num2str(stat_plt_rng));
1963 set(dat.h_t0lineA,'YData',stat_plt_rng);
1964 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1965 dat.times);
1966 h_lineA=plot([1 1]*dat.times(current_tpt),stat_plt_rng,'k');
1967 set(h_lineA,'linewidth',2);
1968 dat.h_lineA=h_lineA;
1969
1970 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1971 'dat=get(gcbf, ''userdata'');' ...
1972 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
1973 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
1974 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
1975 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
1976 'set(dat.fig_id,''userdata'',dat);' ...
1977 'gui_erp(''redraw topo'');' ...
1978 'drawnow;' ...
1979 'clear latpoint dattmp tmppos;' ...
1980 ];
1981 set(dat.h_timeA,'ButtonDownFcn',bdf_code);
1982 set(dat.h_showingA,'ButtonDownFcn',bdf_code);
1983
1984
1985 dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
1986 axes(dat.h_cbarA);
1987 cla;
1988 cbar(dat.h_cbarA);
1989 absmx=round(dat.absmxA*100)/100;
1990 set(gca,'xticklabel',[-absmx 0 absmx]);
1991 h_cbar_title=title(cbar_title);
1992 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1993 end
1994
1995 set(dat.fig_id,'userdata',dat);
1996
1997
1998
1999
2000
2001 function [dat, redraw_wform]=update_test(dat)
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015 crnt_ttest=get(dat.h_ptest,'value');
2016
2017 n_psbl_tests=length(dat.psbl_tests);
2018 crnt_bin=get(dat.h_bin,'value');
2019 redraw_wform=0;
2020 if n_psbl_tests<crnt_ttest,
2021
2022 set(dat.h_testwind,'string',[]);
2023 dat.alpha=[];
2024 dat.critical_t=[];
2025 dat.mltplcmp_crct=[];
2026 set(dat.h_critval,'string',[]);
2027
2028 if ~isequal(dat.loaded_chans,dat.showing_chans)
2029 redraw_wform=1;
2030 end
2031 else
2032 ptest_bin=dat.t_tests(crnt_ttest).bin;
2033 if ptest_bin~=crnt_bin,
2034 redraw_wform=1;
2035 set(dat.h_bin,'value',ptest_bin);
2036 end
2037
2038
2039
2040 crnt_null_mean=dat.null_mean;
2041 if crnt_null_mean~=dat.t_tests(crnt_ttest).null_mean,
2042 redraw_wform=1;
2043 end
2044 dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
2045
2046
2047 test_wind=dat.t_tests(crnt_ttest).time_wind;
2048 dat.n_wind=size(test_wind,1);
2049 wind_edges=[];
2050 for nw=1:dat.n_wind,
2051 if nw==dat.n_wind,
2052 wind_edges=[wind_edges num2str(test_wind(nw,:))];
2053 else
2054 wind_edges=[wind_edges num2str(test_wind(nw,:)) '; '];
2055 end
2056 end
2057 set(dat.h_testwind,'string',wind_edges);
2058
2059
2060
2061 if ~isempty(setdiff(dat.t_tests(crnt_ttest).used_chan_ids, ...
2062 dat.loaded_chans)),
2063 warndlg('The set of t-tests you selected includes some channels that were excluded when you created this GUI. Keep this in mind when interpreting the visualization.','gui_erp Warning');
2064 end
2065
2066
2067
2068 if ~isequal(dat.t_tests(crnt_ttest).used_chan_ids,dat.showing_chans)
2069 redraw_wform=1;
2070 end
2071
2072
2073 if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
2074 dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
2075 dat.mltplcmp_crct='fdr';
2076 else
2077 dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
2078 dat.mltplcmp_crct='perm';
2079 end
2080 dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
2081 set(dat.h_critval,'string',num2str(dat.critical_t));
2082 end
2083 set(dat.fig_id,'userdata',dat);
2084
2085
2086 function redraw_topos(dat,redraw_cbars)
2087
2088 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
2089 dat.times);
2090
2091 test_wind=str2num(get(dat.h_testwind,'string'));
2092 critical_t=str2num(get(dat.h_critval,'string'));
2093
2094 if ~isempty(test_wind) && ~isempty(critical_t),
2095
2096
2097 crnt_ttest=get(dat.h_ptest,'value');
2098 current_tpt_in_ms=dat.times(current_tpt);
2099 n_showing=length(dat.showing_chans);
2100 sig_chans=zeros(1,n_showing);
2101 for nw=1:dat.n_wind,
2102 if (current_tpt_in_ms>=test_wind(nw,1)) && (current_tpt_in_ms<=test_wind(nw,2)),
2103
2104 if ~strcmpi(dat.mltplcmp_crct,'fdr') && (length(critical_t)==1) && isnan(critical_t)
2105
2106 pval_tpt_id=find(dat.t_tests(crnt_ttest).used_tpt_ids==current_tpt);
2107 if ~isempty(pval_tpt_id)
2108
2109 sig_chans_temp=find(dat.t_tests(crnt_ttest).adj_pval(:,pval_tpt_id)<dat.t_tests(crnt_ttest).desired_alphaORq);
2110 sig_chans_temp=dat.t_tests(crnt_ttest).used_chan_ids(sig_chans_temp);
2111 sig_chans=zeros(1,n_showing);
2112 for a=1:n_showing,
2113 if ismember(dat.showing_chans(a),sig_chans_temp)
2114 sig_chans(a)=1;
2115 end
2116 end
2117 end
2118 else
2119 if length(critical_t)==2,
2120
2121
2122 if isnan(critical_t(2))
2123 sig_chans=[];
2124 else
2125 sig_chans(dat.showing_t(:,current_tpt)>max(critical_t))=1;
2126 end
2127 if ~isnan(critical_t(1))
2128 sig_chans(dat.showing_t(:,current_tpt)<min(critical_t))=1;
2129 end
2130 else
2131 if isnan(critical_t)
2132 sig_chans=[];
2133 elseif critical_t>0,
2134 sig_chans(dat.showing_t(:,current_tpt)>critical_t)=1;
2135 else
2136 sig_chans(dat.showing_t(:,current_tpt)<critical_t)=1;
2137 end
2138 end
2139 end
2140 break;
2141 end
2142 end
2143 sig_chans=find(sig_chans>0);
2144 else
2145 sig_chans=[];
2146 end
2147
2148
2149 set(dat.fig_id,'CurrentAxes',dat.h_topoA);
2150
2151 if size(dat.showingA,1)<=2,
2152
2153 topoplotMK(dat.showingA(:,current_tpt),dat.chanlocs(dat.showing_chans), ...
2154 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2155
2156 if get(dat.h_stat,'value')==3,
2157
2158 if redraw_cbars,
2159
2160 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2161 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
2162 'style','blank','plain_blank',1);
2163 end
2164 else
2165
2166 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2167 topoplotMK(dat.showingB(:,current_tpt),dat.chanlocs(dat.showing_chans), ...
2168 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2169 end
2170 else
2171 topoplotMK(dat.showingA(:,current_tpt),dat.chanlocs(dat.showing_chans),'maplimits', ...
2172 [-1 1]*dat.absmxA,'emarker2',{sig_chans,'o',[1 1 1],4});
2173 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2174
2175 if get(dat.h_stat,'value')==3,
2176
2177 if redraw_cbars,
2178
2179 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2180 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
2181 'style','blank','plain_blank',1);
2182 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2183 end
2184 else
2185
2186 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2187 topoplotMK(dat.showingB(:,current_tpt),dat.chanlocs(dat.showing_chans),'maplimits', ...
2188 [-1 1]*dat.absmxB,'emarker2',{sig_chans,'o',[1 1 1],4});
2189 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2190 end
2191 end
2192
2193 if (redraw_cbars)
2194
2195
2196 set(dat.fig_id,'CurrentAxes',dat.h_cbarA);
2197 absmx=round(dat.absmxA*100)/100;
2198 set(gca,'xticklabel',[-absmx 0 absmx]);
2199
2200
2201
2202 set(dat.fig_id,'CurrentAxes',dat.h_cbarB);
2203 absmx=round(dat.absmxB*100)/100;
2204 set(gca,'xticklabel',[-absmx 0 absmx]);
2205 end
2206 drawnow
2207