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 function gui_erp(cmnd_str,varargin)
0327
0328 p=inputParser;
0329 p.addRequired('cmnd_str',@(x) ischar(x) || isstruct(x));
0330 p.addParamValue('fig_id',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1)));
0331 p.addParamValue('bin',1,@(x) isnumeric(x) && (length(x)==1));
0332 p.addParamValue('show_wind',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==2)));
0333 p.addParamValue('GNDorGRP',[],@isstruct);
0334 p.addParamValue('critical_t',[],@(x) isempty(x) || (isnumeric(x) && (length(x)<=2)));
0335 p.addParamValue('test_wind',[],@(x) isempty(x) || (isnumeric(x) && (size(x,2)==2)));
0336 p.addParamValue('ydir',-1,@(x) isnumeric(x) && (length(x)==1));
0337 p.addParamValue('stat','t',@(x) ischar(x) || strcmpi(x,'t') || strcmpi(x,'stder'));
0338 p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0339 p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0340 p.addParamValue('alpha_or_q',[],@(x) isempty(x) || isnumeric(x));
0341 p.addParamValue('t_test',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1) && (x>0)));
0342 p.addParamValue('verblevel',2,@(x) isnumeric(x) && (length(x)==1));
0343 p.parse(cmnd_str,varargin{:});
0344
0345 if ~verLessThan('matlab','8.1')
0346 warning('gui_erp.m does not yet work with your version of Matlab. Try an older version.');
0347 return;
0348 end
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=double(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 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 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>max(critical_t));
0956 sig_chans=[sig_chans; find(dat.showing_t(:,plotted_pts(mx_tpt))<min(critical_t))];
0957 else
0958 if critical_t>0,
0959 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>critical_t);
0960 else
0961 sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))<critical_t);
0962 end
0963 end
0964 end
0965 break;
0966 end
0967 end
0968 end
0969 cbar_title_fontsize=14;
0970 if size(dat.showingA,1)<=2,
0971
0972 topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0973 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
0974 cbar_title='Not Applicable';
0975 cbar_title_fontsize=10;
0976 else
0977 topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0978 'maplimits',[-1 1]*dat.absmxA,'emarker2',{sig_chans,'o',[1 1 1],4});
0979 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
0980 cbar_title='\muV';
0981 end
0982
0983
0984
0985 dat.h_cbarA=axes('position',[0.76 .945 .2 .015]);
0986 cbar(dat.h_cbarA);
0987 absmx=round(dat.absmxA*100)/100;
0988 set(gca,'xticklabel',[-absmx 0 absmx]);
0989 h_cbar_title=title(cbar_title);
0990 set(h_cbar_title,'fontsize',cbar_title_fontsize);
0991
0992
0993
0994
0995 uicontrol(dat.fig_id,...
0996 'Units','normalized', ...
0997 'Position',[ 0.905 0.62 0.07 0.04 ],...
0998 'String','msec',...
0999 'fontsize',14, ...
1000 'fontunits','normalized', ...
1001 'Style','text');
1002 dat.h_topo_time=uicontrol(dat.fig_id,...
1003 'CallBack','gui_erp(''time jump'');',...
1004 'Units','normalized', ...
1005 'Position',[ 0.800 0.62 0.109 0.04 ], ...
1006 'String',num2str(plotted_times(mx_tpt)), ...
1007 'Style','edit', ...
1008 'Enable','on', ...
1009 'ToolTipString','Time point to visualize topographicaly.', ...
1010 'fontsize',14, ...
1011 'fontunits','normalized', ...
1012 'horizontalalignment','center', ...
1013 'BackGroundColor','w', ...
1014 'Tag','topo_time');
1015
1016
1017
1018
1019
1020
1021
1022
1023 uipanel(dat.fig_id,...
1024 'Units','normalized', ...
1025 'Position',[ 0.719 0.175 0.281 0.42 ],...
1026 'shadowcolor','k', ...
1027 'highlightcolor',frm_col, ...
1028 'foregroundcolor',frm_col, ...
1029 'backgroundcolor',frm_col);
1030
1031
1032 dat.h_topoB=axes('position',[0.705 .27 .31 .24],'box','off');
1033
1034 cbar_title_fontsize=14;
1035 if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
1036 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
1037 'style','blank','plain_blank',1);
1038 cbar_title='Not Applicable';
1039 cbar_title_fontsize=10;
1040 else
1041 if size(dat.showingB,1)<=2,
1042
1043 topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1044 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
1045 cbar_title='Not Applicable';
1046 cbar_title_fontsize=10;
1047 else
1048 topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1049 'maplimits',[-1 1]*dat.absmxB,'emarker2',{sig_chans,'o',[1 1 1],4});
1050 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
1051 if strcmpi(p.Results.stat,'t'),
1052 cbar_title='t-score';
1053 else
1054 cbar_title='\muV';
1055 end
1056 end
1057 end
1058
1059
1060 dat.h_cbarB=axes('position',[0.76 .535 .2 .015]);
1061 cbar(dat.h_cbarB);
1062 absmx=round(dat.absmxB*100)/100;
1063 set(gca,'xticklabel',[-absmx 0 absmx]);
1064 h_cbar_title=title(cbar_title);
1065 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1066
1067
1068 dat.h_back1=uicontrol(dat.fig_id,...
1069 'CallBack','gui_erp(''back one'');',...
1070 'Units','normalized', ...
1071 'Position',[ 0.80 0.232 0.055 0.04 ],...
1072 'String','<',...
1073 'fontsize',14, ...
1074 'fontunits','normalized', ...
1075 'Tag','back1', ...
1076 'ToolTipString','Show topography at preceding time point.', ...
1077 'Style','pushbutton');
1078
1079
1080 dat.h_forward1=uicontrol(dat.fig_id,...
1081 'CallBack','gui_erp(''forward one'');',...
1082 'Units','normalized', ...
1083 'Position',[ 0.865 0.232 0.055 0.04 ],...
1084 'String','>', ...
1085 'fontsize',14, ...
1086 'fontunits','normalized', ...
1087 'Tag','forward1', ...
1088 'ToolTipString','Show topography at subsequent time point.', ...
1089 'Style','pushbutton');
1090
1091
1092 dat.h_back=uicontrol(dat.fig_id,...
1093 'CallBack','gui_erp(''back'');',...
1094 'Units','normalized', ...
1095 'Position',[ 0.735 0.232 0.055 0.04 ],...
1096 'String','<<',...
1097 'fontsize',14, ...
1098 'fontunits','normalized', ...
1099 'Tag','back', ...
1100 'interruptible','on', ...
1101 'ToolTipString','Animate topography going backwards in time.', ...
1102 'Style','pushbutton');
1103
1104
1105 dat.h_forward=uicontrol(dat.fig_id,...
1106 'CallBack','gui_erp(''forward'');',...
1107 'Units','normalized', ...
1108 'Position',[ 0.93 0.232 0.055 0.04 ],...
1109 'String','>>',...
1110 'fontsize',14, ...
1111 'fontunits','normalized', ...
1112 'Tag','back', ...
1113 'interruptible','on', ...
1114 'ToolTipString','Animate topography going forwards in time.', ...
1115 'Style','pushbutton');
1116
1117
1118 dat.h_stop=uicontrol(dat.fig_id,...
1119 'CallBack','dat=get(gcbf,''userdata''); dat.interrupt=1; set(dat.fig_id,''userdata'',dat);',...
1120 'Units','normalized', ...
1121 'Position',[ 0.745 0.179 0.23 0.05 ],...
1122 'String','Stop Animation',...
1123 'fontsize',14, ...
1124 'fontunits','normalized', ...
1125 'Tag','stop', ...
1126 'enable','off', ...
1127 'ToolTipString','Stop topography animation.', ...
1128 'Style','pushbutton');
1129
1130
1131
1132
1133
1134
1135
1136
1137 uipanel(dat.fig_id,...
1138 'Units','normalized', ...
1139 'Position',[ 0 0 1 0.178 ],...
1140 'shadowcolor','k', ...
1141 'highlightcolor',frm_col, ...
1142 'foregroundcolor',frm_col, ...
1143 'backgroundcolor',frm_col);
1144
1145
1146
1147 bdesc_str=cell(1,n_bin);
1148 for a=1:n_bin,
1149 bdesc_str{a}=sprintf('Bin %d: %s',a,dat.bindesc{a});
1150 end
1151
1152 uicontrol(dat.fig_id,...
1153 'Units','normalized', ...
1154 'Position',[ 0.01 0.09 0.24 0.075 ],...
1155 'String','Current Bin',...
1156 'fontsize',12, ...
1157 'ToolTipString','Bin to plot in Time x ERP/t-score axis.', ...
1158 'Style','text');
1159
1160 dat.h_bin=uicontrol(dat.fig_id,...
1161 'CallBack','gui_erp(''change bin'');',...
1162 'Units','normalized', ...
1163 'Position',[ 0.015 0.095 0.23 0.04 ],...
1164 'fontsize',12, ...
1165 'String',bdesc_str, ...
1166 'Value',bin, ...
1167 'Style','popup', ...
1168 'ToolTipString','Bin to plot in Time x ERP/t-score axis.', ...
1169 'tag','bin');
1170
1171
1172
1173 ttest_str=cell(1,n_psbl_tests+1);
1174 for a=1:n_psbl_tests,
1175 ttest_str{a}=sprintf('Test %d: Bin %d, Times ',dat.psbl_tests(a),dat.t_tests(a).bin);
1176 n_ttst_wind=size(dat.t_tests(a).time_wind,1);
1177 for b=1:n_ttst_wind,
1178 ttest_str{a}=[ttest_str{a} int2str(dat.t_tests(a).time_wind(b,1)) '-' int2str(dat.t_tests(a).time_wind(b,2)) ','];
1179 end
1180 if length(dat.t_tests(a).crit_t)==2,
1181 ttest_str{a}=[ttest_str{a} ' Two-Tailed,'];
1182 elseif dat.t_tests(a).crit_t<0,
1183 ttest_str{a}=[ttest_str{a} ' Lower-Tailed,'];
1184 else
1185 ttest_str{a}=[ttest_str{a} ' Upper-Tailed,'];
1186 end
1187
1188 if isnan(dat.t_tests(a).estimated_alpha)
1189 ttest_str{a}=[ttest_str{a} sprintf(' q=%.4f',dat.t_tests(a).desired_alphaORq)];
1190 ttest_str{a}=[ttest_str{a} sprintf(', method=%s',dat.t_tests(a).mult_comp_method)];
1191 else
1192 ttest_str{a}=[ttest_str{a} sprintf(' alpha=%.4f',dat.t_tests(a).estimated_alpha)];
1193 end
1194
1195 if dat.t_tests(a).null_mean,
1196 ttest_str{a}=[ttest_str{a} sprintf(', Null Mean=%.4f',dat.t_tests(a).null_mean)];
1197 end
1198 end
1199 ttest_str{n_psbl_tests+1}='None/Manual';
1200
1201
1202 uicontrol(dat.fig_id,...
1203 'Units','normalized', ...
1204 'Position',[ 0.255 0.09 0.24 0.075 ],...
1205 'String','Current Test Result',...
1206 'fontsize',12, ...
1207 'ToolTipString','Set of t-test results to visualize.', ...
1208 'Style','text');
1209
1210 dat.h_ptest=uicontrol(dat.fig_id,...
1211 'CallBack','gui_erp(''change test'');',...
1212 'Units','normalized', ...
1213 'Position',[ 0.26 0.095 0.23 0.04 ],...
1214 'fontsize',12, ...
1215 'String',ttest_str, ...
1216 'Value',crnt_ttest, ...
1217 'Style','popup', ...
1218 'ToolTipString','Set of t-test results to visualize.', ...
1219 'tag','bin');
1220
1221
1222
1223 uicontrol(dat.fig_id,...
1224 'Units','normalized', ...
1225 'Position',[ 0.505 0.09 0.26 0.075 ],...
1226 'String','Test Window(s) [Min Max]:',...
1227 'fontsize',12, ...
1228 'Style','text');
1229
1230 wind_edges=[];
1231 for nw=1:dat.n_wind,
1232 if nw==dat.n_wind,
1233 wind_edges=[wind_edges num2str(test_wind(nw,:))];
1234 else
1235 wind_edges=[wind_edges num2str(test_wind(nw,:)) '; '];
1236 end
1237 end
1238 dat.h_testwind=uicontrol(dat.fig_id,...
1239 'CallBack','gui_erp(''update dashed lines'');',...
1240 'Units','normalized', ...
1241 'fontsize',10, ...
1242 'BackGroundColor','w', ...
1243 'Position',[ 0.525 0.095 0.22 0.04 ],...
1244 'String',wind_edges, ...
1245 'Style','edit', ...
1246 'ToolTipString','Miniumum and maximum time of time window in which hypothesis tests were done.', ...
1247 'tag','timerange');
1248
1249
1250
1251
1252 uicontrol(dat.fig_id,...
1253 'Units','normalized', ...
1254 'Position',[ 0.76 0.09 0.23 0.075 ],...
1255 'String','Critical t-score(s)',...
1256 'fontsize',12, ...
1257 'Style','text');
1258
1259 dat.h_critval=uicontrol(dat.fig_id,...
1260 'CallBack','gui_erp(''update critical t'');',...
1261 'Units','normalized', ...
1262 'fontsize',10, ...
1263 'BackGroundColor','w', ...
1264 'Position',[ 0.79 0.095 0.19 0.04 ],...
1265 'String',num2str(critical_t), ...
1266 'Style','edit', ...
1267 'ToolTipString','Critical t-score(s) for reliable deviation from 0 voltage.', ...
1268 'tag','timerange');
1269
1270
1271 stats={'t-score of ERPs','standard error of ERPs','global field power of ERPs'};
1272
1273 uicontrol(dat.fig_id,...
1274 'Units','normalized', ...
1275 'Position',[ 0.005 0.221 0.09 0.03 ],...
1276 'String','Statistic:',...
1277 'fontsize',12, ...
1278 'ToolTipString','Select what to plot in secondary waveform axis: ERP t-scores, standard error of the mean, or global field power.', ...
1279 'Style','text');
1280
1281 if strcmpi(p.Results.stat,'gfp') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
1282
1283
1284 ini_val=3;
1285 elseif strcmpi(p.Results.stat,'t'),
1286 ini_val=1;
1287 elseif strcmpi(p.Results.stat,'stder'),
1288 ini_val=2;
1289 else
1290 error('Unrecognized value of input argument ''stat''.');
1291 end
1292 dat.h_stat=uicontrol(dat.fig_id,...
1293 'CallBack','gui_erp(''change stat'');',...
1294 'Units','normalized', ...
1295 'Position',[ 0.005 0.19 0.16 0.03 ],...
1296 'fontsize',12, ...
1297 'value',ini_val, ...
1298 'String',stats, ...
1299 'Style','popup', ...
1300 'ToolTipString','Plot ERP t-scores or standard error of the mean in secondary axis?', ...
1301 'tag','stat');
1302
1303
1304
1305 uicontrol(dat.fig_id,...
1306 'Units','normalized', ...
1307 'Position',[ 0.01 0.005 0.24 0.075 ],...
1308 'String','Time Range [Min Max]',...
1309 'fontsize',12, ...
1310 'Style','text');
1311
1312 dat.h_timerange=uicontrol(dat.fig_id,...
1313 'CallBack','gui_erp(''new time limits'');',...
1314 'Units','normalized', ...
1315 'fontsize',10, ...
1316 'BackGroundColor','w', ...
1317 'Position',[ 0.025 0.007 0.21 0.04 ],...
1318 'String',num2str(dat.plt_times), ...
1319 'Style','edit', ...
1320 'ToolTipString','Miniumum and maximum time on Time x ERP axis.', ...
1321 'tag','timerange');
1322
1323
1324
1325 uicontrol(dat.fig_id,...
1326 'Units','normalized', ...
1327 'Position',[ 0.26 0.005 0.26 0.075 ],...
1328 'String','ERP Range [Min Max] ',...
1329 'HorizontalAlignment','center', ...
1330 'fontsize',12, ...
1331 'Style','text');
1332
1333 dat.h_statrangeA=uicontrol(dat.fig_id,...
1334 'CallBack','gui_erp(''new statistic limitsA'');',...
1335 'Units','normalized', ...
1336 'fontsize',10, ...
1337 'BackGroundColor','w', ...
1338 'Position',[ 0.28 0.007 0.16 0.04 ],...
1339 'String',num2str(round(vA(3:4)*100)/100), ...
1340 'ToolTipString','Miniumum and maximum voltage on Time x ERP axis.', ...
1341 'Style','edit', ...
1342 'tag','statrange');
1343
1344
1345
1346 uicontrol(dat.fig_id,...
1347 'Units','normalized', ...
1348 'Position',[ 0.50 0.005 0.26 0.075 ],...
1349 'String',' t/StdErr Range [Min Max]',...
1350 'HorizontalAlignment','center', ...
1351 'fontsize',12, ...
1352 'Style','text');
1353
1354 dat.h_statrangeB=uicontrol(dat.fig_id,...
1355 'CallBack','gui_erp(''new statistic limitsB'');',...
1356 'Units','normalized', ...
1357 'fontsize',10, ...
1358 'BackGroundColor','w', ...
1359 'Position',[ 0.54 0.007 0.16 0.04 ],...
1360 'String',num2str(round(vB(3:4)*100)/100), ...
1361 'ToolTipString','Miniumum and maximum t-scores/voltage on Time x t-Scores/Standard Error/GFP axis.', ...
1362 'Style','edit', ...
1363 'tag','statrange');
1364
1365
1366 uicontrol(dat.fig_id,...
1367 'CallBack','close(gcbf);',...
1368 'Units','normalized', ...
1369 'Position',[ 0.77 0.012 0.11 0.05 ],...
1370 'String','Close',...
1371 'fontsize',12, ...
1372 'Tag','close', ...
1373 'backgroundcolor','m', ...
1374 'ToolTipString','Close GUI', ...
1375 'Style','pushbutton');
1376
1377 dat.help_msg=sprintf(['Hold mouse cursor over a GUI control for an explanation of what it does.\n\n', ...
1378 'Time x waveform axis visualizes ERPs, t-score of ERPs, standard error of ERPs, or ERP global field power simultaneously at multiple electrodes. ' ...
1379 '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', ...
1380 'at that point in time.\n\nClick on electrodes in scalp topography to see electrode name.\n\n', ...
1381 'This GUI was produced by gui_erp.m']);
1382
1383
1384 uicontrol(dat.fig_id,...
1385 'CallBack','dat=get(gcbf,''userdata''); helpdlg(dat.help_msg,''ERP GUI Help'');', ...
1386 'Units','normalized', ...
1387 'Position',[ 0.885 0.012 0.11 0.05 ],...
1388 'String','Help',...
1389 'fontsize',12, ...
1390 'Tag','help', ...
1391 'ToolTipString','Click for help', ...
1392 'Style','pushbutton');
1393 dat.interrupt=1;
1394 set(dat.fig_id,'userdata',dat);
1395 elseif strcmpi(cmnd_str,'time jump'),
1396 new_tpt=find_tpt(str2num(get(dat.h_topo_time,'string')), ...
1397 dat.times);
1398 if new_tpt<dat.start_pt,
1399 errordlg('That time is too early.');
1400 elseif new_tpt>dat.end_pt,
1401 errordlg('That time is too late.');
1402 else
1403 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1404 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1405 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1406 set(dat.fig_id,'userdata',dat);
1407 redraw_topos(dat,0);
1408 drawnow;
1409 end
1410 elseif strcmpi(cmnd_str,'back one'),
1411 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1412 dat.times);
1413 new_tpt=current_tpt-1;
1414 if new_tpt<dat.start_pt,
1415 errordlg('Can''t go back any further.');
1416 else
1417 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1418 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1419 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1420 set(dat.fig_id,'userdata',dat);
1421 redraw_topos(dat,0);
1422 drawnow;
1423 end
1424 elseif strcmpi(cmnd_str,'forward one'),
1425 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1426 dat.times);
1427 new_tpt=current_tpt+1;
1428 if new_tpt>dat.end_pt,
1429 errordlg('Can''t go forward any further.');
1430 else
1431 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1432 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1433 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1434 set(dat.fig_id,'userdata',dat);
1435 redraw_topos(dat,0);
1436 drawnow;
1437 end
1438 elseif strcmpi(cmnd_str,'back'),
1439 interrupt=0;
1440 dat.interrupt=0;
1441 set(dat.h_stop,'enable','on');
1442 set(dat.h_forward,'enable','off');
1443 set(dat.h_back,'enable','off');
1444 set(dat.h_forward1,'enable','off');
1445 set(dat.h_back1,'enable','off');
1446 set(dat.fig_id,'userdata',dat);
1447 drawnow;
1448 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1449 dat.times);
1450 new_tpt=current_tpt-1;
1451 loop_ct=0;
1452 while (new_tpt>=dat.start_pt) && (interrupt~=1),
1453 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1454 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1455 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1456 drawnow('update');
1457 redraw_topos(dat,0);
1458 drawnow;
1459 new_tpt=new_tpt-1;
1460 loop_ct=loop_ct+1;
1461 if loop_ct==5,
1462 loop_ct=0;
1463 new_tmp=get(dat.fig_id,'userdata');
1464 interrupt=new_tmp.interrupt;
1465 end
1466 end
1467 drawnow;
1468 dat.interrupt=0;
1469 new_tpt=new_tpt+1;
1470 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1471 set(dat.h_stop,'enable','off');
1472 set(dat.h_forward,'enable','on');
1473 set(dat.h_back,'enable','on');
1474 set(dat.h_forward1,'enable','on');
1475 set(dat.h_back1,'enable','on');
1476 set(dat.fig_id,'userdata',dat);
1477 elseif strcmpi(cmnd_str,'forward'),
1478 interrupt=0;
1479 dat.interrupt=0;
1480 set(dat.h_stop,'enable','on');
1481 set(dat.h_forward,'enable','off');
1482 set(dat.h_back,'enable','off');
1483 set(dat.h_forward1,'enable','off');
1484 set(dat.h_back1,'enable','off');
1485 set(dat.fig_id,'userdata',dat);
1486 drawnow;
1487 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1488 dat.times);
1489 new_tpt=current_tpt+1;
1490 loop_ct=0;
1491 while (new_tpt<=dat.end_pt) && (interrupt~=1),
1492 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1493 set(dat.h_lineA,'XData',[1 1]*dat.times(new_tpt));
1494 set(dat.h_lineB,'XData',[1 1]*dat.times(new_tpt));
1495 drawnow('update');
1496 redraw_topos(dat,0);
1497 drawnow;
1498 new_tpt=new_tpt+1;
1499 loop_ct=loop_ct+1;
1500 if loop_ct==5,
1501 loop_ct=0;
1502 new_tmp=get(dat.fig_id,'userdata');
1503 interrupt=new_tmp.interrupt;
1504 end
1505 end
1506 drawnow;
1507 dat.interrupt=0;
1508 new_tpt=new_tpt-1;
1509 set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
1510 set(dat.h_stop,'enable','off');
1511 set(dat.h_forward,'enable','on');
1512 set(dat.h_back,'enable','on');
1513 set(dat.h_forward1,'enable','on');
1514 set(dat.h_back1,'enable','on');
1515 set(dat.fig_id,'userdata',dat);
1516 elseif strcmpi(cmnd_str,'change stat'),
1517 stat=get(dat.h_stat,'value');
1518 current_bin=get(dat.h_bin,'value');
1519 if (stat~=3),
1520
1521 if isinf(dat.t_scores(1,1,current_bin)) || isnan(dat.t_scores(1,1,current_bin))
1522 stat=3;
1523 set(dat.h_stat,'value',stat);
1524 if (stat==2)
1525 warndlg('Only one participant contributed to this bin. Thus the grand average standard error cannot be esimated.','gui_erp Warning');
1526 else
1527 warndlg('Only one participant contributed to this bin. Thus the grand average t-scores cannot be derived.','gui_erp Warning');
1528 end
1529 end
1530 end
1531
1532 if (stat==1),
1533
1534 if ~isempty(dat.h_crit1),
1535 delete(dat.h_crit1);
1536 end
1537 if ~isempty(dat.h_crit2),
1538 delete(dat.h_crit2);
1539 end
1540 dat.h_crit1=[];
1541 dat.h_crit2=[];
1542
1543 if ~isempty(dat.h_alph1),
1544 delete(dat.h_alph1);
1545 end
1546 if ~isempty(dat.h_alph2),
1547 delete(dat.h_alph2);
1548 end
1549 dat.h_alph1=[];
1550 dat.h_alph2=[];
1551 end
1552
1553
1554 draw_waveforms(dat,0);
1555 gui_erp('update dashed lines');
1556 elseif strcmpi(cmnd_str,'change bin'),
1557 new_bin=get(dat.h_bin,'value');
1558 crnt_ttest_id=get(dat.h_ptest,'value');
1559 n_t_tests=length(dat.t_tests);
1560 if (crnt_ttest_id==(n_t_tests+1)) || (dat.t_tests(crnt_ttest_id).bin~=new_bin),
1561
1562
1563
1564
1565
1566 crnt_ttest_id=n_t_tests+1;
1567 for a=1:n_t_tests,
1568 if dat.t_tests(a).bin==new_bin;
1569 crnt_ttest_id=a;
1570 break;
1571 end
1572 end
1573 set(dat.h_ptest,'value',crnt_ttest_id);
1574 dat=update_test(dat);
1575 end
1576 draw_waveforms(dat,1);
1577 gui_erp('update dashed lines');
1578 elseif strcmpi(cmnd_str,'new time limits'),
1579
1580 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1581 tme_lim=str2num(get(dat.h_timerange,'string'));
1582 if length(tme_lim)~=2,
1583 errordlg('Enter exactly two values for time range (desired Min and Max values).','gui_erp Error');
1584 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1585 elseif tme_lim(2)<tme_lim(1),
1586 errordlg('The second time range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1587 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1588 elseif (tme_lim(1)<dat.times(1)) || (tme_lim(2)>dat.times(end))
1589 errordlg(sprintf('Time range values must be between %d and %d msec.',dat.times(1),dat.times(end)),'gui_erp Error');
1590 set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)]));
1591 else
1592
1593 set(dat.h_timeA,'xlim',tme_lim);
1594 set(dat.h_timeB,'xlim',tme_lim);
1595 dat.start_pt=find_tpt(tme_lim(1),dat.times);
1596 dat.end_pt=find_tpt(tme_lim(2),dat.times);
1597
1598
1599 dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
1600 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1601 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1602 dat.times);
1603 if (current_tpt>dat.end_pt) || (current_tpt<dat.start_pt)
1604
1605
1606
1607 [dummy, mx_tpt]=max(max(abs(dat.showing_t(:,dat.start_pt:dat.end_pt))));
1608 showing_pts=dat.start_pt:dat.end_pt;
1609 set(dat.h_lineA,'xdata',[1 1]*dat.times(showing_pts(mx_tpt)));
1610 set(dat.h_lineB,'xdata',[1 1]*dat.times(showing_pts(mx_tpt)));
1611
1612 set(dat.h_topo_time,'string',num2str(dat.times(showing_pts(mx_tpt))));
1613 end
1614
1615 redraw_topos(dat,1);
1616 set(dat.fig_id,'userdata',dat);
1617 end
1618 elseif strcmpi(cmnd_str,'new statistic limitsA'),
1619
1620 plotted_limits=get(dat.h_timeA,'ylim');
1621 new_lim=str2num(get(dat.h_statrangeA,'string'));
1622 if length(new_lim)~=2,
1623 errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_erp Error');
1624 set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1625 elseif new_lim(2)<new_lim(1),
1626 errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1627 set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1628 else
1629
1630 set(dat.h_timeA,'ylim',new_lim);
1631 set(dat.h_t0lineA,'YData',new_lim);
1632 set(dat.h_lineA,'YData',new_lim);
1633
1634
1635 if ~isempty(dat.h_wind1A)
1636 set(dat.h_wind1A,'YData',new_lim);
1637 set(dat.h_wind2A,'YData',new_lim);
1638 end
1639 end
1640 elseif strcmpi(cmnd_str,'new statistic limitsB'),
1641
1642 plotted_limits=get(dat.h_timeB,'ylim');
1643 new_lim=str2num(get(dat.h_statrangeB,'string'));
1644 if length(new_lim)~=2,
1645 errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_erp Error');
1646 set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1647 elseif new_lim(2)<new_lim(1),
1648 errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_erp Error');
1649 set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)]));
1650 else
1651
1652 set(dat.h_timeB,'ylim',new_lim);
1653 set(dat.h_t0lineB,'YData',new_lim);
1654 set(dat.h_lineB,'YData',new_lim);
1655
1656
1657 if ~isempty(dat.h_wind1B)
1658 set(dat.h_wind1B,'YData',new_lim);
1659 set(dat.h_wind2B,'YData',new_lim);
1660 end
1661 end
1662 elseif strcmpi(cmnd_str,'redraw topo'),
1663 redraw_topos(dat,1);
1664 elseif strcmpi(cmnd_str,'update dashed lines'),
1665 test_wind=str2num(get(dat.h_testwind,'string'));
1666
1667 if (size(test_wind,2)>2) || (isempty(test_wind) && ~isempty(get(dat.h_testwind,'string')))
1668 errordlg('Enter pairs of values for time window range (desired Min and Max values) or leave box blank. Separate multiple pairs with semicolons.', ...
1669 'gui_erp Error');
1670 elseif length(dat.critical_t)>2,
1671 errordlg('Enter one (for one-tailed test) or two (for two-tailed test) value(s) for critical t-scores or leave box blank.', ...
1672 'gui_erp Error');
1673 else
1674 if isempty(test_wind),
1675 test_wind=[NaN NaN];
1676 end
1677
1678
1679 if ~isempty(dat.h_crit1),
1680 delete(dat.h_crit1);
1681 end
1682 if ~isempty(dat.h_crit2),
1683 delete(dat.h_crit2);
1684 end
1685 if ~isempty(dat.h_alph1),
1686 delete(dat.h_alph1);
1687 end
1688 if ~isempty(dat.h_alph2),
1689 delete(dat.h_alph2);
1690 end
1691 if ~isempty(dat.h_wind1A),
1692 delete(dat.h_wind1A);
1693 end
1694 if ~isempty(dat.h_wind2A),
1695 delete(dat.h_wind2A);
1696 end
1697 if ~isempty(dat.h_wind1B),
1698 delete(dat.h_wind1B);
1699 end
1700 if ~isempty(dat.h_wind2B),
1701 delete(dat.h_wind2B);
1702 end
1703 dat.h_wind1A=[];
1704 dat.h_wind2A=[];
1705 dat.h_wind1B=[];
1706 dat.h_wind2B=[];
1707 dat.h_crit1=[];
1708 dat.h_crit2=[];
1709 dat.h_alph1=[];
1710 dat.h_alph2=[];
1711 dat.n_wind=size(test_wind,1);
1712
1713 if ~sum(isnan(test_wind))
1714 y_rngA=get(dat.h_timeA,'YLim');
1715 y_rngB=get(dat.h_timeB,'YLim');
1716
1717 axes(dat.h_timeA);
1718 for nw=1:dat.n_wind,
1719 dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),y_rngA,'k--');
1720 set(dat.h_wind1A(nw),'linewidth',2);
1721 dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),y_rngA,'k--');
1722 set(dat.h_wind2A(nw),'linewidth',2);
1723 end
1724
1725 axes(dat.h_timeB);
1726 for nw=1:dat.n_wind,
1727 dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),y_rngB,'k--');
1728 set(dat.h_wind1B(nw),'linewidth',2);
1729 dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),y_rngB,'k--');
1730 set(dat.h_wind2B(nw),'linewidth',2);
1731 end
1732
1733
1734 stat=get(dat.h_stat,'value');
1735
1736
1737 if ~sum(isnan(dat.critical_t)) && (stat==1) && ~isempty(dat.critical_t)
1738 for nw=1:dat.n_wind,
1739 dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(1),'r--');
1740 set(dat.h_crit1(nw),'linewidth',3);
1741 if nw==1,
1742
1743 tm_rng=double(dat.times(end)-dat.times(1));
1744 if strcmpi(dat.mltplcmp_crct,'fdr')
1745 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1746 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1747 else
1748 dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1749 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1750 end
1751 set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
1752 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1753 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1754 end
1755 if length(dat.critical_t)>1,
1756 dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(2),'r--');
1757 set(dat.h_crit2(nw),'linewidth',3);
1758 if nw==1,
1759
1760 if strcmpi(dat.mltplcmp_crct,'fdr')
1761 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1762 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1763 else
1764 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1765 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1766 end
1767 set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
1768 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1769 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1770 end
1771 end
1772 end
1773 end
1774 end
1775 set(dat.fig_id,'userdata',dat);
1776 redraw_topos(dat,1);
1777 end
1778 elseif strcmpi(cmnd_str,'update critical t'),
1779 critical_t=str2num(get(dat.h_critval,'string'));
1780 if ~isequal(sort(critical_t),sort(dat.critical_t)),
1781 new_alpha=[];
1782 while isempty(new_alpha),
1783 new_alpha=inputdlg({'Enter alpha level for new critical t-score(s)'}, ...
1784 'Set New Alpha Level',1,{num2str(dat.alpha)});
1785 new_alpha=str2num(new_alpha{1});
1786 if isempty(new_alpha),
1787 errrodlg('You must enter a numeric value for the new alpha level','gui_erp Error');
1788 end
1789 end
1790 dat.alpha=new_alpha;
1791 dat.critical_t=critical_t;
1792 end
1793 set(dat.fig_id,'userdata',dat);
1794 gui_erp('update dashed lines');
1795 elseif strcmpi(cmnd_str,'change test'),
1796 [dat, redraw_wform]=update_test(dat);
1797 if redraw_wform,
1798 draw_waveforms(dat,1);
1799 end
1800 gui_erp('update dashed lines');
1801 else
1802 errordlg(sprintf('Command "%s" not recognized by gui_erp.m',cmnd_str), ...
1803 'gui_erp Error');
1804 end
1805
1806
1807 function draw_waveforms(dat,redrawA)
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817 new_bin=get(dat.h_bin,'value');
1818 stat=get(dat.h_stat,'value');
1819 crnt_ttest_id=get(dat.h_ptest,'value');
1820 n_t_tests=length(dat.t_tests);
1821 if crnt_ttest_id==n_t_tests+1,
1822
1823 dat.showing_chans=dat.loaded_chans;
1824 else
1825 dat.showing_chans=intersect(dat.t_tests(crnt_ttest_id).used_chan_ids, ...
1826 dat.loaded_chans);
1827 end
1828
1829
1830 axes(dat.h_timeB);
1831 delete(dat.h_showingB);
1832 delete(dat.h_lineB);
1833 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1834
1835 if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1836
1837 dat.showing_t=squeeze( (dat.erp(dat.showing_chans,:,new_bin)- ...
1838 dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1839 else
1840 dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1841 end
1842
1843 if (stat==1),
1844 dat.showingB=dat.showing_t;
1845 cbar_title='t-score';
1846 ylab='t-score';
1847 elseif (stat==2),
1848 dat.showingB=squeeze(dat.stder(dat.showing_chans,:,new_bin));
1849 cbar_title='\muV';
1850 ylab='\muV (StdEr)';
1851 elseif (stat==3),
1852 dat.showingB=dat.gfp(:,new_bin)';
1853 cbar_title='\muV';
1854 ylab='\muV (GFP)';
1855 end
1856 if size(dat.showingB,1)==1,
1857
1858 dat.h_showingB=plot(dat.times,dat.showingB);
1859 cbar_title='Not Applicable';
1860 cbar_title_fontsize=10;
1861 else
1862 dat.h_showingB=plot(dat.times,dat.showingB');
1863 cbar_title_fontsize=14;
1864 end
1865 set(dat.h_time_ylabB,'string',ylab);
1866
1867 stat_mx=max(max(dat.showingB));
1868 stat_mn=min(min(dat.showingB));
1869
1870 if isnan(stat_mx) || isnan(stat_mn)
1871 error('Bin %d does not appear to have any data in it.',new_bin);
1872 end
1873 stat_rng=stat_mx-stat_mn;
1874 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1875 stat_plt_rng=round(stat_plt_rng*100)/100;
1876 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
1877 set(dat.h_statrangeB,'string',num2str(stat_plt_rng));
1878 set(dat.h_t0lineB,'YData',stat_plt_rng);
1879 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1880 dat.times);
1881 h_lineB=plot([1 1]*dat.times(current_tpt),stat_plt_rng,'k');
1882 set(h_lineB,'linewidth',2);
1883 dat.h_lineB=h_lineB;
1884
1885 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1886 'dat=get(gcbf, ''userdata'');' ...
1887 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
1888 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
1889 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
1890 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
1891 'set(dat.fig_id,''userdata'',dat);' ...
1892 'gui_erp(''redraw topo'');' ...
1893 'drawnow;' ...
1894 'clear latpoint dattmp tmppos;' ...
1895 ];
1896 set(dat.h_showingB,'ButtonDownFcn',bdf_code);
1897 set(dat.h_timeB,'ButtonDownFcn',bdf_code);
1898
1899
1900 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1901 axes(dat.h_cbarB);
1902 cla;
1903 cbar(dat.h_cbarB);
1904 absmx=round(dat.absmxB*100)/100;
1905 set(gca,'xticklabel',[-absmx 0 absmx]);
1906 h_cbar_title=title(cbar_title);
1907 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1908
1909 if redrawA,
1910
1911 new_title=['Bin ' int2str(new_bin) ': ' dat.bindesc{new_bin}];
1912 title_max_char=43;
1913 if length(new_title)>title_max_char,
1914 new_title=new_title(1:title_max_char);
1915 end
1916 set(dat.h_time_title,'string',new_title);
1917
1918
1919
1920 axes(dat.h_timeA);
1921 delete(dat.h_showingA);
1922 delete(dat.h_lineA);
1923 plotted_times=dat.times(dat.start_pt:dat.end_pt);
1924
1925 if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1926
1927 dat.showing_t=squeeze( (dat.erp(dat.showing_chans,:,new_bin)- ...
1928 dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1929 else
1930 dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1931 end
1932
1933 dat.showingA=squeeze(dat.erp(dat.showing_chans,:,new_bin));
1934 cbar_title='\muV';
1935 ylab='\muV (ERP)';
1936 if size(dat.showingA,1)==1,
1937
1938 dat.h_showingA=plot(dat.times,dat.showingA);
1939 cbar_title='Not Applicable';
1940 cbar_title_fontsize=10;
1941 else
1942 dat.h_showingA=plot(dat.times,dat.showingA');
1943 end
1944 set(dat.h_time_ylabA,'string',ylab);
1945
1946 stat_mx=max(max(dat.showingA));
1947 stat_mn=min(min(dat.showingA));
1948 stat_rng=stat_mx-stat_mn;
1949 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1950 stat_plt_rng=round(stat_plt_rng*100)/100;
1951 axis([plotted_times(1) plotted_times(end) stat_plt_rng]);
1952 set(dat.h_statrangeA,'string',num2str(stat_plt_rng));
1953 set(dat.h_t0lineA,'YData',stat_plt_rng);
1954 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
1955 dat.times);
1956 h_lineA=plot([1 1]*dat.times(current_tpt),stat_plt_rng,'k');
1957 set(h_lineA,'linewidth',2);
1958 dat.h_lineA=h_lineA;
1959
1960 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1961 'dat=get(gcbf, ''userdata'');' ...
1962 'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
1963 'set(dat.h_lineA,''XData'',[1 1]*dat.times(new_tpt));' ...
1964 'set(dat.h_lineB,''XData'',[1 1]*dat.times(new_tpt));' ...
1965 'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
1966 'set(dat.fig_id,''userdata'',dat);' ...
1967 'gui_erp(''redraw topo'');' ...
1968 'drawnow;' ...
1969 'clear latpoint dattmp tmppos;' ...
1970 ];
1971 set(dat.h_timeA,'ButtonDownFcn',bdf_code);
1972 set(dat.h_showingA,'ButtonDownFcn',bdf_code);
1973
1974
1975 dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
1976 axes(dat.h_cbarA);
1977 cla;
1978 cbar(dat.h_cbarA);
1979 absmx=round(dat.absmxA*100)/100;
1980 set(gca,'xticklabel',[-absmx 0 absmx]);
1981 h_cbar_title=title(cbar_title);
1982 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1983 end
1984
1985 set(dat.fig_id,'userdata',dat);
1986
1987
1988
1989
1990
1991 function [dat, redraw_wform]=update_test(dat)
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005 crnt_ttest=get(dat.h_ptest,'value');
2006
2007 n_psbl_tests=length(dat.psbl_tests);
2008 crnt_bin=get(dat.h_bin,'value');
2009 redraw_wform=0;
2010 if n_psbl_tests<crnt_ttest,
2011
2012 set(dat.h_testwind,'string',[]);
2013 dat.alpha=[];
2014 dat.critical_t=[];
2015 dat.mltplcmp_crct=[];
2016 set(dat.h_critval,'string',[]);
2017
2018 if ~isequal(dat.loaded_chans,dat.showing_chans)
2019 redraw_wform=1;
2020 end
2021 else
2022 ptest_bin=dat.t_tests(crnt_ttest).bin;
2023 if ptest_bin~=crnt_bin,
2024 redraw_wform=1;
2025 set(dat.h_bin,'value',ptest_bin);
2026 end
2027
2028
2029
2030 crnt_null_mean=dat.null_mean;
2031 if crnt_null_mean~=dat.t_tests(crnt_ttest).null_mean,
2032 redraw_wform=1;
2033 end
2034 dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
2035
2036
2037 test_wind=dat.t_tests(crnt_ttest).time_wind;
2038 dat.n_wind=size(test_wind,1);
2039 wind_edges=[];
2040 for nw=1:dat.n_wind,
2041 if nw==dat.n_wind,
2042 wind_edges=[wind_edges num2str(test_wind(nw,:))];
2043 else
2044 wind_edges=[wind_edges num2str(test_wind(nw,:)) '; '];
2045 end
2046 end
2047 set(dat.h_testwind,'string',wind_edges);
2048
2049
2050
2051 if ~isempty(setdiff(dat.t_tests(crnt_ttest).used_chan_ids, ...
2052 dat.loaded_chans)),
2053 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');
2054 end
2055
2056
2057
2058 if ~isequal(dat.t_tests(crnt_ttest).used_chan_ids,dat.showing_chans)
2059 redraw_wform=1;
2060 end
2061
2062
2063 if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
2064 dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
2065 dat.mltplcmp_crct='fdr';
2066 else
2067 dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
2068 dat.mltplcmp_crct='perm';
2069 end
2070 dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
2071 set(dat.h_critval,'string',num2str(dat.critical_t));
2072 end
2073 set(dat.fig_id,'userdata',dat);
2074
2075
2076 function redraw_topos(dat,redraw_cbars)
2077
2078 current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
2079 dat.times);
2080
2081 test_wind=str2num(get(dat.h_testwind,'string'));
2082 critical_t=str2num(get(dat.h_critval,'string'));
2083
2084 if ~isempty(test_wind) && ~isempty(critical_t),
2085
2086
2087 crnt_ttest=get(dat.h_ptest,'value');
2088 current_tpt_in_ms=dat.times(current_tpt);
2089 n_showing=length(dat.showing_chans);
2090 sig_chans=zeros(1,n_showing);
2091 for nw=1:dat.n_wind,
2092 if (current_tpt_in_ms>=test_wind(nw,1)) && (current_tpt_in_ms<=test_wind(nw,2)),
2093 if isnan(critical_t)
2094
2095 pval_tpt_id=find(dat.t_tests(crnt_ttest).used_tpt_ids==current_tpt);
2096 if ~isempty(pval_tpt_id)
2097
2098 sig_chans_temp=find(dat.t_tests(crnt_ttest).adj_pval(:,pval_tpt_id)<dat.t_tests(crnt_ttest).desired_alphaORq);
2099 sig_chans_temp=dat.t_tests(crnt_ttest).used_chan_ids(sig_chans_temp);
2100 sig_chans=zeros(1,n_showing);
2101 for a=1:n_showing,
2102 if ismember(dat.showing_chans(a),sig_chans_temp)
2103 sig_chans(a)=1;
2104 end
2105 end
2106 end
2107 else
2108 if length(critical_t)==2,
2109 sig_chans(dat.showing_t(:,current_tpt)>max(critical_t))=1;
2110 sig_chans(dat.showing_t(:,current_tpt)<min(critical_t))=1;
2111 else
2112 if critical_t>0,
2113 sig_chans(dat.showing_t(:,current_tpt)>critical_t)=1;
2114 else
2115 sig_chans(dat.showing_t(:,current_tpt)<critical_t)=1;
2116 end
2117 end
2118 end
2119 break;
2120 end
2121 end
2122 sig_chans=find(sig_chans>0);
2123 else
2124 sig_chans=[];
2125 end
2126
2127
2128 set(dat.fig_id,'CurrentAxes',dat.h_topoA);
2129
2130 if size(dat.showingA,1)<=2,
2131
2132 topoplotMK(dat.showingA(:,current_tpt),dat.chanlocs(dat.showing_chans), ...
2133 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2134
2135 if get(dat.h_stat,'value')==3,
2136
2137 if redraw_cbars,
2138
2139 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2140 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
2141 'style','blank','plain_blank',1);
2142 end
2143 else
2144
2145 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2146 topoplotMK(dat.showingB(:,current_tpt),dat.chanlocs(dat.showing_chans), ...
2147 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2148 end
2149 else
2150 topoplotMK(dat.showingA(:,current_tpt),dat.chanlocs(dat.showing_chans),'maplimits', ...
2151 [-1 1]*dat.absmxA,'emarker2',{sig_chans,'o',[1 1 1],4});
2152 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2153
2154 if get(dat.h_stat,'value')==3,
2155
2156 if redraw_cbars,
2157
2158 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2159 topoplotMK([],dat.chanlocs(dat.showing_chans), ...
2160 'style','blank','plain_blank',1);
2161 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2162 end
2163 else
2164
2165 set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2166 topoplotMK(dat.showingB(:,current_tpt),dat.chanlocs(dat.showing_chans),'maplimits', ...
2167 [-1 1]*dat.absmxB,'emarker2',{sig_chans,'o',[1 1 1],4});
2168 set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
2169 end
2170 end
2171
2172 if (redraw_cbars)
2173
2174
2175 set(dat.fig_id,'CurrentAxes',dat.h_cbarA);
2176 absmx=round(dat.absmxA*100)/100;
2177 set(gca,'xticklabel',[-absmx 0 absmx]);
2178
2179
2180
2181 set(dat.fig_id,'CurrentAxes',dat.h_cbarB);
2182 absmx=round(dat.absmxB*100)/100;
2183 set(gca,'xticklabel',[-absmx 0 absmx]);
2184 end
2185 drawnow
2186