0001 function gui_erpimage(command_str)
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 global MK_HIST
0086
0087 if nargin == 0
0088 command_str = 'initialize';
0089 end
0090
0091
0092 if ~strcmpi(command_str,'initialize')
0093 h_fig = gcf;
0094 if ~strcmp(get(h_fig,'tag'),'gui_erpimage')
0095
0096
0097 h_figs = get(0,'children');
0098 h_fig = findobj(h_figs,'flat',...
0099 'tag','gui_erpimage');
0100 if isempty(h_fig)
0101
0102
0103
0104 gui_erpimage('initialize');
0105 gui_erpimage(command_str);
0106 return;
0107 end
0108 end
0109
0110
0111
0112
0113
0114
0115
0116 dat_tmp=get(gcf,'userdata');
0117 h_avewidth=dat_tmp.h_avewidth;
0118 h_topo=dat_tmp.h_topo;
0119 h_chan=dat_tmp.h_chan;
0120 h_bins=dat_tmp.h_bins;
0121 h_bins2=dat_tmp.h_bins2;
0122 h_in_fname=dat_tmp.h_in_fname;
0123 h_in_fnameB=dat_tmp.h_in_fnameB;
0124 h_sort_var=dat_tmp.h_sort_var;
0125 h_avewidth=dat_tmp.h_avewidth;
0126 h_erps=dat_tmp.h_erps;
0127 h_plotsvar=dat_tmp.h_plotsvar;
0128 h_alignsvar=dat_tmp.h_alignsvar;
0129 h_plothead=dat_tmp.h_plothead;
0130 h_figid=dat_tmp.h_figid;
0131 h_r_figid=dat_tmp.h_r_figid;
0132 h_title=dat_tmp.h_title;
0133 h_splithalf=dat_tmp.h_splithalf;
0134 h_timerange=dat_tmp.h_timerange;
0135 h_erprange=dat_tmp.h_erprange;
0136 h_eimrange=dat_tmp.h_eimrange;
0137 h_decimate=dat_tmp.h_decimate;
0138 h_marktrials=dat_tmp.h_marktrials;
0139 h_marktimes=dat_tmp.h_marktimes;
0140 h_create=dat_tmp.h_create;
0141 h_other=dat_tmp.h_other;
0142 h_cmprchan=dat_tmp.h_cmprchan;
0143 end
0144
0145
0146
0147 if strcmp(command_str,'initialize')
0148
0149
0150
0151
0152 h_figs = get(0,'children');
0153 h_fig = findobj(h_figs,'flat',...
0154 'tag','gui_erpimage');
0155 if ~isempty(h_fig)
0156 figure(h_fig(1));
0157 return
0158 end
0159
0160 h_fig = figure('name','ERPimage GUI','tag','gui_erpimage', ...
0161 'MenuBar','none');
0162 pos=get(h_fig,'position');
0163 set(h_fig,'position',[pos(1:2) 660 520]);
0164
0165 clear dat_tmp;
0166
0167
0168 dat_tmp.chanlocs(1).theta=0;
0169 dat_tmp.chanlocs(1).radius=0.5;
0170 dat_tmp.chanlocs(1).labels='MiPf';
0171 dat_tmp.chanlocs(1).sph_theta=0;
0172 dat_tmp.chanlocs(1).sph_phi=0;
0173 dat_tmp.chanlocs(1).X=1;
0174 dat_tmp.chanlocs(1).Y=0;
0175 dat_tmp.chanlocs(1).Z=0;
0176 dat_tmp.chanlocs(1).urchan=3;
0177 dat_tmp.chanlocs(1).sph_radius=[];
0178 dat_tmp.chanlocs(1).type=[];
0179
0180 dat_tmp.chanlocs(2).theta=0;
0181 dat_tmp.chanlocs(2).radius=0;
0182 dat_tmp.chanlocs(2).labels='MiCe';
0183 dat_tmp.chanlocs(2).sph_theta=0;
0184 dat_tmp.chanlocs(2).sph_phi=90;
0185 dat_tmp.chanlocs(2).X=6.1232e-17;
0186 dat_tmp.chanlocs(2).Y=0;
0187 dat_tmp.chanlocs(2).Z=1;
0188 dat_tmp.chanlocs(2).urchan=16;
0189 dat_tmp.chanlocs(2).sph_radius=[];
0190 dat_tmp.chanlocs(2).type=[];
0191
0192 dat_tmp.chanlocs(3).theta=180;
0193 dat_tmp.chanlocs(3).radius=0.5;
0194 dat_tmp.chanlocs(3).labels='MiOc';
0195 dat_tmp.chanlocs(3).sph_theta=-180;
0196 dat_tmp.chanlocs(3).sph_phi=0;
0197 dat_tmp.chanlocs(3).X=-1;
0198 dat_tmp.chanlocs(3).Y=-1.2246e-16;
0199 dat_tmp.chanlocs(3).Z=0;
0200 dat_tmp.chanlocs(3).urchan=28;
0201 dat_tmp.chanlocs(3).sph_radius=[];
0202 dat_tmp.chanlocs(3).type=[];
0203
0204
0205
0206
0207
0208
0209 h_frame_top = uicontrol(h_fig,...
0210 'Units','normalized', ...
0211 'Position',[ 0 0.9 1 0.3 ],...
0212 'Style','frame');
0213 frm_col=get(h_frame_top,'backgroundcolor');
0214
0215
0216 h_in_fnameB=uicontrol(h_fig,...
0217 'CallBack',['h_in_fname=findobj(gcf,''tag'',''in_fname'');' ...
0218 '[in_fname, in_pathname]=uigetfile(''*.eim'',''Select ERPimage .eim data file'');' ...
0219 'if in_fname, ', ...
0220 'set(h_in_fname,''string'',[in_pathname in_fname]);' ...
0221 'gui_erpimage(''load data''); end;'], ...
0222 'Units','normalized', ...
0223 'Position',[ 0.03 0.92 0.15 0.06 ],...
0224 'String','Input File',...
0225 'ToolTipString','Click to find *.eim file containing EEG and sorting variables', ...
0226 'Style','pushbutton');
0227
0228
0229 h_in_fname=uicontrol(h_fig,...
0230 'CallBack','gui_erpimage(''load data'');',...
0231 'Units','normalized', ...
0232 'Position',[ 0.18 0.92 0.8 0.06 ], ...
0233 'String','None', ...
0234 'Style','edit', ...
0235 'Enable','on', ...
0236 'BackGroundColor','w', ...
0237 'Tag','in_fname');
0238 align([h_in_fnameB h_in_fname],'VerticalAlignment','center');
0239
0240
0241
0242
0243 h_panel_left=uipanel(h_fig,...
0244 'Units','normalized', ...
0245 'Position',[ 0 0 .255 0.9 ],...
0246 'shadowcolor','k', ...
0247 'highlightcolor',frm_col, ...
0248 'foregroundcolor',frm_col, ...
0249 'backgroundcolor',frm_col);
0250
0251
0252 uicontrol(h_fig,...
0253 'Units','normalized', ...
0254 'Position',[ 0.048 0.82 0.16 0.07 ],...
0255 'String','Basic Parameters',...
0256 'FontWeight','bold', ...
0257 'Style','text');
0258
0259
0260
0261 h_chanB=uicontrol(h_fig,...
0262 'CallBack',['dat_tmp=get(gcf,''UserData'');' ...
0263 'if isempty(dat_tmp.chans)' ...
0264 ' errordlg(''No channels loaded'');' ...
0265 'else' ...
0266 ' [tmps,ok] = listdlg(''PromptString'', ''Select Channel'', ''SelectionMode'',''single'',''ListString'', dat_tmp.chans);' ...
0267 ' if ok' ...
0268 ' set(dat_tmp.h_chan, ''string'', dat_tmp.chans{tmps});' ...
0269 ' gui_erpimage(''check chan'');' ...
0270 ' end;' ...
0271 'end;' ...
0272 'clear tmps ok;'], ...
0273 'Units','normalized', ...
0274 'Position',[ 0.068 0.79 0.12 0.05 ],...
0275 'String','Channel',...
0276 'Style','pushbutton', ...
0277 'enable','off', ...
0278 'ToolTipString',sprintf('Click button for list of loaded channels.\nClick electrodes on cartoon head to see electrode name.\nGray electrodes are not loaded in memory.'),...
0279 'horizontalalignment','center', ...
0280 'tag','chanB');
0281
0282
0283 h_topo=axes('position',[0.01 .56 .235 .23],'box','off');
0284 warning('off');
0285 topoplotMK(zeros(31,1),dat_tmp.chanlocs,'ecolor',[1 1 1]*.7, ...
0286 'emarkersize',12, ...
0287 'headcolor',[1 1 1]*.5);
0288 warning('on');
0289 set(h_topo,'color',frm_col);
0290 set(h_fig,'color',frm_col);
0291
0292
0293
0294 h_chan=uicontrol(h_fig,...
0295 'CallBack','gui_erpimage(''check chan'');',...
0296 'Units','normalized', ...
0297 'Position',[ 0.0425 0.49 0.17 0.07 ],...
0298 'String','Not Specified',...
0299 'Style','edit', ...
0300 'enable','off', ...
0301 'horizontalalignment','center', ...
0302 'tag','chan');
0303
0304
0305
0306
0307 uicontrol(h_fig,...
0308 'Units','normalized', ...
0309 'Position',[ 0.043 0.38 0.17 0.07 ],...
0310 'String','Sorting Variable',...
0311 'ToolTipString','Variable according to which the single trials will be sorted.', ...
0312 'Style','text');
0313
0314 h_sort_var=uicontrol(h_fig,...
0315 'CallBack',[],...
0316 'Units','normalized', ...
0317 'Position',[ 0.015 0.34 0.225 0.07 ],...
0318 'String','Sorting Variable',...
0319 'Style','popup', ...
0320 'enable','off', ...
0321 'ToolTipString','Variable according to which the single trials will be sorted.', ...
0322 'tag','sort_var');
0323
0324
0325
0326
0327 uicontrol(h_fig,...
0328 'CallBack',['dat_tmp=get(gcf,''UserData'');' ...
0329 'if isempty(dat_tmp.eim_bins)' ...
0330 ' errordlg(''No data loaded'');' ...
0331 'else' ...
0332 ' ct=0; str=cell(1,length(dat_tmp.eim_bins)); for a=dat_tmp.eim_bins, ct=ct+1; str{ct}=[num2str(a) '': '' dat_tmp.bindesc{a}]; end;' ...
0333 ' [tmps,ok] = listdlg(''PromptString'', ''Select Bin'',''SelectionMode'',''multiple'',''ListString'',str);' ...
0334 ' if ok' ...
0335 ' curr_str=get(dat_tmp.h_bins,''string'');' ...
0336 ' if strcmpi(curr_str,''All''), curr_str=[]; end;' ...
0337 ' new_str=[curr_str '' '' num2str(dat_tmp.eim_bins(tmps))];' ...
0338 ' new_str=num2str(unique(str2num(new_str)));' ...
0339 ' set(dat_tmp.h_bins, ''string'',new_str);' ...
0340 ' end;' ...
0341 'end;' ...
0342 'clear tmps ok;'], ...
0343 'Units','normalized', ...
0344 'Position',[ 0.0775 0.27 0.10 0.05 ],...
0345 'String','Bin(s)',...
0346 'Style','pushbutton', ...
0347 'enable','off', ...
0348 'ToolTipString','Click for list of loaded bins.',...
0349 'tag','binsB');
0350
0351 h_bins=uicontrol(h_fig,...
0352 'CallBack','gui_erpimage(''check bins'');', ...
0353 'Units','normalized', ...
0354 'Position',[ 0.015 0.21 0.225 0.06 ],...
0355 'String','All',...
0356 'Style','edit', ...
0357 'enable','off', ...
0358 'tag','bins');
0359
0360
0361
0362
0363 uicontrol(h_fig,...
0364 'Units','normalized', ...
0365 'Position',[ 0.015 0.10 0.225 0.07 ],...
0366 'String','Smoothing Factor(trials/stdev)',...
0367 'ToolTipString',sprintf(['Width of Gaussian-weighted vertical moving average.\n' ...
0368 'Larger numbers produce greater smoothing (0=no smoothing).']), ...
0369 'Style','text');
0370 h_avewidth=uicontrol(h_fig,...
0371 'CallBack',[],...
0372 'Units','normalized', ...
0373 'Position',[ 0.0775 0.035 0.1 0.07 ],...
0374 'String','0',...
0375 'Style','edit', ...
0376 'enable','off', ...
0377 'tag','avewidth');
0378
0379
0380
0381
0382
0383
0384 uicontrol(h_fig,...
0385 'Units','normalized', ...
0386 'Position',[ 0.253 0.235 .747 0.665 ],...
0387 'Style','frame');
0388
0389 uicontrol(h_fig,...
0390 'Units','normalized', ...
0391 'Position',[ 0.4975 0.82 0.26 0.07 ],...
0392 'String','Additional Parameters',...
0393 'FontWeight','bold', ...
0394 'Style','text');
0395
0396
0397
0398 uicontrol(h_fig,...
0399 'Units','normalized', ...
0400 'Position',[ 0.28 0.76 0.08 0.06 ],...
0401 'String','Title:',...
0402 'HorizontalAlignment','left', ...
0403 'ToolTipString','Title of ERPimage that will be created. Default is channel name and bin descriptors.', ...
0404 'Style','text');
0405
0406 h_title=uicontrol(h_fig,...
0407 'Units','normalized', ...
0408 'Position',[ 0.33 0.78 0.65 0.06 ],...
0409 'String','Default', ...
0410 'Style','edit', ...
0411 'enable','off', ...
0412 'tag','eim_title');
0413
0414
0415
0416 uicontrol(h_fig,...
0417 'Units','normalized', ...
0418 'Position',[ 0.28 0.69 0.10 0.06 ],...
0419 'String','Figure #:',...
0420 'HorizontalAlignment','left', ...
0421 'ToolTipString','The number of the figure window in which the ERPimage will be created.', ...
0422 'Style','text');
0423
0424 h_figid=uicontrol(h_fig,...
0425 'Units','normalized', ...
0426 'Position',[ 0.365 0.71 0.16 0.06 ],...
0427 'String','New Window', ...
0428 'Style','edit', ...
0429 'enable','off', ...
0430 'tag','figid');
0431
0432
0433
0434 uicontrol(h_fig,...
0435 'Units','normalized', ...
0436 'Position',[ 0.28 0.625 0.07 0.06 ],...
0437 'String','ERP(s):',...
0438 'HorizontalAlignment','left', ...
0439 'ToolTipString','Number of ERPs to plot under the ERPimage. Multiple ERPs are produced by splitting trials into equal portions.', ...
0440 'Style','text');
0441
0442 h_erps=uicontrol(h_fig,...
0443 'Units','normalized', ...
0444 'Position',[ 0.35 0.627 0.1 0.06 ],...
0445 'String',[0:4],...
0446 'Value',2, ...
0447 'Style','popup', ...
0448 'enable','off', ...
0449 'tag','erps');
0450
0451
0452
0453 uicontrol(h_fig,...
0454 'Units','normalized', ...
0455 'Position',[ 0.28 0.57 0.16 0.06 ],...
0456 'String','ERP Range in uV (Min Max):',...
0457 'HorizontalAlignment','left', ...
0458 'ToolTipString','uV range for ERP(s). Default is min and max ERP voltage.', ...
0459 'Style','text');
0460
0461 h_erprange=uicontrol(h_fig,...
0462 'CallBack','gui_erpimage(''check limits'');',...
0463 'Units','normalized', ...
0464 'Position',[ 0.445 0.575 0.16 0.06 ],...
0465 'String','No Data', ...
0466 'Style','edit', ...
0467 'enable','off', ...
0468 'tag','erprange');
0469
0470
0471
0472 uicontrol(h_fig,...
0473 'Units','normalized', ...
0474 'Position',[ 0.28 0.45 0.16 0.1 ],...
0475 'String','ERPimage uV Range (Min Max):',...
0476 'HorizontalAlignment','left', ...
0477 'ToolTipString','ERPimage colorbar uV range. Default is -/+ max(abs(voltage in entire ERPimage)).', ...
0478 'Style','text');
0479
0480 h_eimrange=uicontrol(h_fig,...
0481 'CallBack','gui_erpimage(''check limits'');',...
0482 'Units','normalized', ...
0483 'Position',[ 0.445 0.49 0.16 0.06 ],...
0484 'String','No Data', ...
0485 'Style','edit', ...
0486 'enable','off', ...
0487 'tag','eimrange');
0488
0489
0490
0491 uicontrol(h_fig,...
0492 'Units','normalized', ...
0493 'Position',[ 0.28 0.40 0.16 0.065 ],...
0494 'String','Time Range in msec (Min Max):',...
0495 'HorizontalAlignment','left', ...
0496 'ToolTipString','Time range to image. Default is min and max time points.', ...
0497 'Style','text');
0498
0499 h_timerange=uicontrol(h_fig,...
0500 'CallBack','gui_erpimage(''check limits'');',...
0501 'Units','normalized', ...
0502 'Position',[ 0.445 0.405 0.16 0.06 ],...
0503 'String','No Data', ...
0504 'Style','edit', ...
0505 'enable','off', ...
0506 'tag','timerange');
0507
0508
0509
0510
0511 uicontrol(h_fig,...
0512 'Units','normalized', ...
0513 'Position',[ 0.28 0.305 0.12 0.06 ],...
0514 'String','Mark Trials:',...
0515 'HorizontalAlignment','left', ...
0516 'ToolTipString','Add horizontal blue line(s) at this/these trial number(s).', ...
0517 'Style','text');
0518
0519 h_marktrials=uicontrol(h_fig,...
0520 'Units','normalized', ...
0521 'Position',[ 0.39 0.325 0.16 0.06 ],...
0522 'String','None', ...
0523 'Style','edit', ...
0524 'enable','off', ...
0525 'tag','marktrials');
0526
0527
0528
0529 uicontrol(h_fig,...
0530 'Units','normalized', ...
0531 'Position',[ 0.28 0.245 0.08 0.05 ],...
0532 'String','Other:',...
0533 'HorizontalAlignment','left', ...
0534 'ToolTipString','ERPimage arguments not listed can be specified here (press Help for a list of options).', ...
0535 'Style','text');
0536
0537 h_other=uicontrol(h_fig,...
0538 'Units','normalized', ...
0539 'Position',[ 0.35 0.25 0.63 0.06 ],...
0540 'String',[], ...
0541 'Style','edit', ...
0542 'BackGroundColor','w', ...
0543 'enable','off', ...
0544 'tag','other_opts');
0545
0546
0547
0548
0549
0550
0551
0552
0553 temp=uicontrol(h_fig,...
0554 'Units','normalized', ...
0555 'Position',[ 0.65 0.663 0.2 0.09],...
0556 'String','Trial Decimation Factor:',...
0557 'HorizontalAlignment','left', ...
0558 'ToolTipString','Use less than the full number of trials (e.g., 2=use every other trial).', ...
0559 'Style','text');
0560
0561 h_decimate=uicontrol(h_fig,...
0562 'Units','normalized', ...
0563 'Position',[ 0.86 0.71 0.1 0.06 ],...
0564 'String','0', ...
0565 'Style','edit', ...
0566 'enable','off', ...
0567 'tag','decimate');
0568
0569
0570 h_plothead=uicontrol(h_fig,...
0571 'Units','normalized', ...
0572 'Position',[ 0.65 0.65 0.25 0.06 ],...
0573 'String','Show Cartoon Head',...
0574 'HorizontalAlignment','left', ...
0575 'Style','radiobutton', ...
0576 'Value',1, ...
0577 'enable','off', ...
0578 'ToolTipString','Add cartoon head indicating electrode position to ERPimage.', ...
0579 'tag','plothead');
0580
0581
0582 h_plotsvar=uicontrol(h_fig,...
0583 'Units','normalized', ...
0584 'Position',[ 0.65 0.59 0.2 0.06 ],...
0585 'String','Show Sort Var',...
0586 'HorizontalAlignment','left', ...
0587 'Style','radiobutton', ...
0588 'Value',1, ...
0589 'enable','off', ...
0590 'ToolTipString','Plot sorting variable value on top of ERPimage.', ...
0591 'tag','plotsvar');
0592
0593
0594 h_alignsvar=uicontrol(h_fig,...
0595 'Units','normalized', ...
0596 'Position',[ 0.65 0.54 0.28 0.06 ],...
0597 'String',sprintf('Align to Sorting Variable'),...
0598 'Style','radiobutton', ...
0599 'HorizontalAlignment','left', ...
0600 'Value',0, ...
0601 'ToolTipString','Align trials to sorting variable instead of event onset.', ...
0602 'enable','off', ...
0603 'tag','alignsvar');
0604
0605
0606
0607 uicontrol(h_fig,...
0608 'Units','normalized', ...
0609 'Position',[ 0.65 0.44 0.16 0.09 ],...
0610 'String','Sorting Var Range (Min Max):',...
0611 'HorizontalAlignment','left', ...
0612 'ToolTipString','Range (in units of sorting variable to image and make ERPs from. Only works if sorting trials by sorting variable (e.g., it won''t work if you sort by phase). Default is min and max of sorting variable (after smoothing).', ...
0613 'Style','text');
0614
0615 h_sortvarrange=uicontrol(h_fig,...
0616 'CallBack','gui_erpimage(''check limits'');',...
0617 'Units','normalized', ...
0618 'Position',[ 0.82 0.475 0.16 0.06 ],...
0619 'String','No Data', ...
0620 'Style','edit', ...
0621 'enable','off', ...
0622 'tag','sortvarrange');
0623
0624 uicontrol(h_fig,...
0625 'CallBack',['tmp=get(gcf,''userdata''); svars=get(tmp.h_sort_var,''string'');' ...
0626 'id=get(tmp.h_sort_var,''value''); gui_svar_cdf(''initialize'',get(tmp.h_in_fname,''string''),svars{id},get(tmp.h_bins,''string''),1);'],...
0627 'Units','normalized', ...
0628 'Position',[ 0.67 0.405 0.29 0.065 ],...
0629 'String','Sorting Var Distribution',...
0630 'Tag','plot_sort_var', ...
0631 'Enable','off', ...
0632 'ToolTipString','Create GUI to explore sorting variable''s cumulative distribution. Useful for picking a range of sorting variable values to image. Only trials falling into the bins specified under "Basic Parameters" are considered.', ...
0633 'Style','pushbutton');
0634
0635
0636
0637 uicontrol(h_fig,...
0638 'Units','normalized', ...
0639 'Position',[ 0.65 0.32 0.12 0.06 ],...
0640 'String','Mark Times (in msec):',...
0641 'HorizontalAlignment','left', ...
0642 'ToolTipString','Add vertical dashed line(s) at this/these time(s).', ...
0643 'Style','text');
0644
0645 h_marktimes=uicontrol(h_fig,...
0646 'Units','normalized', ...
0647 'Position',[ 0.76 0.325 0.16 0.06 ],...
0648 'String','None', ...
0649 'Style','edit', ...
0650 'enable','off', ...
0651 'tag','marktimes');
0652
0653
0654
0655
0656
0657
0658 uicontrol(h_fig,...
0659 'Units','normalized', ...
0660 'Position',[ 0.253 0.09 .747 0.145],...
0661 'Style','frame');
0662
0663 uicontrol(h_fig,...
0664 'Units','normalized', ...
0665 'Position',[ 0.4975 0.17 0.26 0.06 ],...
0666 'String','Compare ERPimages',...
0667 'FontWeight','bold', ...
0668 'Style','text');
0669
0670
0671 h_splithalf=uicontrol(h_fig,...
0672 'Units','normalized', ...
0673 'CallBack','gui_erpimage(''deactivate compare'');', ...
0674 'Position',[ 0.27 0.17 0.15 0.06 ],...
0675 'String','Split Half',...
0676 'Style','radiobutton', ...
0677 'Value',0, ...
0678 'enable','off', ...
0679 'ToolTipString','Create two ERPimages from even and odd trials (useful for getting a sense of reliability).', ...
0680 'HorizontalAlignment','left', ...
0681 'tag','splithalf');
0682
0683
0684 uicontrol(h_fig,...
0685 'Units','normalized', ...
0686 'Position',[ 0.27 0.108 0.15 0.03 ],...
0687 'String','Channel',...
0688 'Style','text', ...
0689 'ToolTipString','Compare ERPimages from primary channel and this secondary channel. "None" deactivates comparing ERPimages.', ...
0690 'HorizontalAlignment','left');
0691
0692 h_cmprchan=uicontrol(h_fig,...
0693 'CallBack',['tmp=get(gcf,''userdata'');', ...
0694 'if (get(tmp.h_cmprchan,''value'')~=length(get(tmp.h_cmprchan,''string''))), ' ...
0695 ' set(tmp.h_splithalf,''value'',0);', ...
0696 ' gui_erpimage(''check bins'');', ...
0697 'else, ', ...
0698 ' gui_erpimage(''deactivate compare''); ' ...
0699 'end;'], ...
0700 'Units','normalized', ...
0701 'Position',[ 0.345 0.11 0.15 0.03 ], ...
0702 'String','None', ...
0703 'Style','popup', ...
0704 'enable','off', ...
0705 'ToolTipString','Compare ERPimages from primary channel and this secondary channel. "None" deactivates comparing ERPimages.', ...
0706 'tag','cmprchan');
0707
0708
0709
0710 uicontrol(h_fig,...
0711 'CallBack',['h_in_fname2=findobj(gcf,''tag'',''in_fname2''); ', ...
0712 '[in_fname2, in_pathname2]=uigetfile(''*.eim'',''Select ERPimage .eim data file'');', ...
0713 'if in_fname2, ', ...
0714 'set(h_in_fname2,''string'',[in_pathname2 in_fname2]);', ...
0715 'tmp=get(gcf,''UserData'');', ...
0716 'set(tmp.h_splithalf,''value'',0);', ...
0717 'gui_erpimage(''update contrast file'');', ...
0718 'gui_erpimage(''check bins''); end;'], ...
0719 'Units','normalized', ...
0720 'Position',[ 0.5675 0.15 0.12 0.05 ],...
0721 'String','Input File',...
0722 'Enable','off', ...
0723 'ToolTipString','Click to find secondary *.eim file containing EEG and sorting variables', ...
0724 'Style','pushbutton');
0725
0726 h_in_fname2=uicontrol(h_fig,...
0727 'Units','normalized', ...
0728 'CallBack','gui_erpimage(''update contrast file'');', ...
0729 'Position',[ 0.5125 0.10 0.23 0.05 ],...
0730 'String','None', ...
0731 'Style','edit', ...
0732 'Enable','off', ...
0733 'ToolTipString',['Secondary *.eim file to contrast with primary *.eim file. "None" deactivates comparing ERPimages.' 10 '"Primary File" means that all data come from primary ERPimage file.'], ...
0734 'Tag','in_fname2');
0735
0736
0737
0738
0739 uicontrol(h_fig,...
0740 'CallBack',['dat_tmp=get(gcf,''UserData'');' ...
0741 'if isempty(dat_tmp.eim_bins2)' ...
0742 ' errordlg(''No secondary bins loaded'');' ...
0743 'else' ...
0744 ' ct=1; str=cell(1,length(dat_tmp.eim_bins2)+1); str{1}=''None''; for a=dat_tmp.eim_bins2, ct=ct+1; str{ct}=[num2str(a) '': '' dat_tmp.bindesc2{a}]; end;' ...
0745 ' [tmps,ok] = listdlg(''PromptString'', ''Select Bin'',''SelectionMode'',''multiple'',''ListString'',str);' ...
0746 ' if ok' ...
0747 ' curr_str=get(dat_tmp.h_bins2,''string'');' ...
0748 ' if strcmpi(curr_str,''None''), curr_str=[]; end;' ...
0749 ' if strcmpi(curr_str,''All''), curr_str=num2str(dat_tmp.eim_bins2); end;' ...
0750 ' if (tmps==1), ', ...
0751 ' gui_erpimage(''deactivate compare''); ', ...
0752 ' else, new_str=[curr_str '' '' num2str(dat_tmp.eim_bins2(setdiff(tmps-1,0)))];' ...
0753 ' new_str=num2str(unique(str2num(new_str))); ', ...
0754 ' set(dat_tmp.h_bins2,''string'',new_str);', ...
0755 ' set(dat_tmp.h_splithalf,''value'',0);', ...
0756 ' gui_erpimage(''check bins'');', ...
0757 ' end;' ...
0758 ' end;' ...
0759 ' clear tmps ok;', ...
0760 'end;'], ...
0761 'Units','normalized', ...
0762 'Position',[ 0.83 0.15 0.10 0.05 ],...
0763 'String','Bin(s)',...
0764 'Style','pushbutton', ...
0765 'enable','off', ...
0766 'ToolTipString','Click for list of possible bins. "None" deactivates comparing ERPimages.',...
0767 'tag','binsB');
0768
0769 h_bins2=uicontrol(h_fig,...
0770 'CallBack',['tmp=get(gcf,''userdata''); ', ...
0771 'if strcmpi(get(tmp.h_bins2,''string''),''None''), ', ...
0772 ' gui_erpimage(''deactivate compare''); ', ...
0773 'else, gui_erpimage(''check bins''); end; ', ...
0774 'set(tmp.h_splithalf,''value'',0);'], ...
0775 'Units','normalized', ...
0776 'Position',[ 0.765 0.10 0.22 0.05 ],...
0777 'String','None',...
0778 'Style','edit', ...
0779 'enable','off', ...
0780 'ToolTipString','Bin(s) to contrast with the bin(s) listed under "Basic Parameters". "None" deactivates comparing ERPimages.',...
0781 'tag','bins');
0782
0783
0784
0785
0786
0787
0788
0789 uicontrol(h_fig,...
0790 'Style','frame',...
0791 'Units','normalized', ...
0792 'Position',[ 0.253 0.001 .747 0.09 ]);
0793
0794
0795
0796 uicontrol(h_fig,...
0797 'CallBack','gui_erpimage(''write_hist'');', ...
0798 'Units','normalized', ...
0799 'Position',[ 0.465 0.01 0.10 0.07 ],...
0800 'String','History',...
0801 'Enable','off', ...
0802 'Tag','history', ...
0803 'ToolTipString','Write this session''s history of commands to a text file. Useful for creating scripts.', ...
0804 'Style','pushbutton');
0805
0806
0807 uicontrol(h_fig,...
0808 'CallBack','close(gcf);',...
0809 'Units','normalized', ...
0810 'Position',[ 0.258 0.01 0.10 0.07 ],...
0811 'String','Cancel',...
0812 'Tag','cancel', ...
0813 'ToolTipString','Close GUI', ...
0814 'backgroundcolor','m', ...
0815 'Style','pushbutton');
0816
0817 dat_tmp.help_msg=sprintf(['Hold mouse cursor over a GUI control for an explanation of what it does.\n\n', ...
0818 'Click on electrodes in scalp topography to see electrode name.\n\n', ...
0819 'This GUI creates ERPimages to visualize the relationship between the EEG at an electrode and some other experimental variable. ' ...
0820 'See MatlabMK and EEGLAB documentation for further help.\n\n', ...
0821 'Type ''help plot_erpimageMK'' to see a full list of optional ERPimage options.\n\n' ...
0822 'This GUI was produced by gui_erpimage.m']);
0823
0824
0825 uicontrol(h_fig,...
0826 'CallBack','dat=get(gcf,''userdata''); helpdlg(dat.help_msg,''ERPimage GUI Help'');', ...
0827 'Units','normalized', ...
0828 'Position',[ 0.36 0.01 0.10 0.07 ],...
0829 'String','Help',...
0830 'Tag','help', ...
0831 'ToolTipString','GUI/ERPimage help window', ...
0832 'Style','pushbutton');
0833
0834
0835 uicontrol(h_fig,...
0836 'CallBack','gui_erpimage(''Plot r'');',...
0837 'Units','normalized', ...
0838 'Position',[ 0.57 0.01 0.10 0.07 ],...
0839 'String','Plot r',...
0840 'Tag','plot_r', ...
0841 'enable','off', ...
0842 'ToolTipString',sprintf(['Plot correlation between sorting variable and EEG at all channels.\n', ...
0843 'Useful for identifying interesting channels to ERPimage.']), ...
0844 'Style','pushbutton');
0845
0846 h_r_figid=uicontrol(h_fig,...
0847 'CallBack','gui_erpimage(''Check r_figid'');',...
0848 'Units','normalized', ...
0849 'Position',[ 0.67 0.02 0.08 0.055 ],...
0850 'String','New', ...
0851 'Style','edit', ...
0852 'enable','off', ...
0853 'ToolTipString',sprintf(['# of Matlab window in which correlations will be plotted after ' ...
0854 'pressing "Plot r" button.\n"New" means a new window will be created.']), ...
0855 'tag','r_figid');
0856
0857
0858 h_create=uicontrol(h_fig,...
0859 'CallBack','gui_erpimage(''Create ERPimage'');',...
0860 'Units','normalized', ...
0861 'Position',[ 0.76 0.01 0.23 0.07 ],...
0862 'String','Create ERPimage',...
0863 'tag','create', ...
0864 'enable','off', ...
0865 'ToolTipString','Once parameters have been chosen, press this button to create the ERPimage.', ...
0866 'Style','pushbutton');
0867
0868 dat_tmp.h_avewidth=h_avewidth;
0869 dat_tmp.h_topo=h_topo;
0870 dat_tmp.h_chan=h_chan;
0871 dat_tmp.h_in_fname=h_in_fname;
0872 dat_tmp.h_in_fnameB=h_in_fnameB;
0873 dat_tmp.h_in_fname2=h_in_fname2;
0874 dat_tmp.h_sort_var=h_sort_var;
0875 dat_tmp.h_bins=h_bins;
0876 dat_tmp.h_bins2=h_bins2;
0877 dat_tmp.h_erps=h_erps;
0878 dat_tmp.h_plotsvar=h_plotsvar;
0879 dat_tmp.h_plothead=h_plothead;
0880 dat_tmp.h_alignsvar=h_alignsvar;
0881 dat_tmp.h_title=h_title;
0882 dat_tmp.h_figid=h_figid;
0883 dat_tmp.h_r_figid=h_r_figid;
0884 dat_tmp.h_splithalf=h_splithalf;
0885 dat_tmp.h_timerange=h_timerange;
0886 dat_tmp.h_erprange=h_erprange;
0887 dat_tmp.h_decimate=h_decimate;
0888 dat_tmp.h_marktrials=h_marktrials;
0889 dat_tmp.h_marktimes=h_marktimes;
0890 dat_tmp.h_create=h_create;
0891 dat_tmp.h_other=h_other;
0892 dat_tmp.h_cmprchan=h_cmprchan;
0893 dat_tmp.h_sortvarrange=h_sortvarrange;
0894 dat_tmp.h_eimrange=h_eimrange;
0895 dat_tmp.chans=[];
0896 dat_tmp.eim_bins=[];
0897 dat_tmp.ep_times=[];
0898 set(gcf,'userdata',dat_tmp);
0899
0900 elseif strcmpi(command_str,'load data'),
0901
0902
0903
0904
0905 try
0906 loaded=1;
0907 in_fname=get(h_in_fname,'string');
0908 fprintf('Loading ERPimage data from %s.\n',in_fname);
0909 load(in_fname,'-MAT');
0910 catch
0911 loaded=0;
0912
0913 for a=get(gcf,'children')',
0914 f=fieldnames(set(a));
0915 for b=1:length(f),
0916 if strcmpi(f{b},'Callback') && ~strcmpi('cancel',get(a,'Tag')) && ...
0917 ~strcmpi('help',get(a,'Tag'))
0918 set(a,'enable','off');
0919 break;
0920 end
0921 end
0922 end
0923
0924 set(h_in_fname,'enable','on');
0925 set(h_in_fnameB,'enable','on');
0926 err=lasterror;
0927 h_efig = errordlg(err.message,'Input File Error','on');
0928 end
0929
0930 if loaded,
0931 dat_tmp=get(h_fig,'UserData');
0932
0933
0934 if isempty(MK_HIST)
0935 MK_HIST{1}=sprintf('load(''%s'',''-MAT'');',in_fname);
0936 else
0937 MK_HIST{length(MK_HIST)+1}=sprintf('load(''%s'',''-MAT'');',in_fname);
0938 end
0939
0940
0941
0942 fldnms=fieldnames(ep_info);
0943 if isempty(rtmsec)
0944 possible{1}='Not Specified';
0945 srt_var_ct=0;
0946 else
0947 possible{1}='rtmsec';
0948 srt_var_ct=1;
0949 end
0950 for a=1:length(fldnms),
0951 if strcmpi('event',fldnms{a}(1:5)) && ~strcmpi('eventrtmsec',fldnms{a}) && ...
0952 (length(fldnms{a})>5) && ~strcmpi('eventduration',fldnms{a}) && ~strcmpi('eventlatency',fldnms{a}),
0953
0954
0955
0956
0957 cmnd=['isnumeric(ep_info(a).' fldnms{a} ')'];
0958 if (eval(cmnd)),
0959 srt_var_ct=srt_var_ct+1;
0960 possible{srt_var_ct}=fldnms{a}(6:end);
0961 end
0962 end
0963 end
0964 set(h_sort_var,'value',1,'string',possible);
0965
0966
0967 axes(h_topo);
0968 nchans=length(chanlocs);
0969 loaded_chans=[];
0970 for a=1:nchans,
0971 for b=1:length(chans),
0972 if strcmpi(chanlocs(a).labels,chans{b})
0973 loaded_chans=[loaded_chans a];
0974 break;
0975 end
0976 end
0977 end
0978 unloaded_chans=setdiff(1:nchans,loaded_chans);
0979 warning('off');
0980 topoplotMK(zeros(length(chanlocs),1),chanlocs, ...
0981 'emarker',{'.','k',10}, ...
0982 'emarkersize',12, ...
0983 'headcolor',[1 1 1]*.5, ...
0984 'emarker2',{unloaded_chans,'.',[.7 .7 .7],10});
0985 warning('on');
0986
0987
0988 set(h_chan,'string',chans{1});
0989 new_chan=findobj(h_topo,'tag',str2lowcase(strtok(chans{1})));
0990 crnt_markersize=get(new_chan,'markersize');
0991 set(new_chan,'color','r','markersize',round(crnt_markersize*1.25));
0992
0993
0994 set(h_timerange,'string',[num2str(ep_times(1)) ' ' num2str(ep_times(end))]);
0995 set(h_erprange,'string','Default');
0996 set(dat_tmp.h_sortvarrange,'string','Default');
0997 set(h_eimrange,'string','Default');
0998
0999
1000 set(h_bins,'String','All');
1001
1002
1003
1004 if strcmpi(get(dat_tmp.h_in_fname2,'String'),'None')
1005
1006 dat_tmp.bindesc2=bindesc;
1007 dat_tmp.eim_bins2=eim_bins;
1008
1009
1010 cmpr_chans=chans;
1011 n_chans=length(chans);
1012 cmpr_chans{n_chans+1}='None';
1013 set(h_cmprchan,'value',n_chans+1,'string',cmpr_chans);
1014 end
1015
1016
1017
1018 dat_tmp.crnt_chan=chans{1};
1019 dat_tmp.markersize=crnt_markersize;
1020 dat_tmp.ep_info=ep_info;
1021 dat_tmp.ep_time=ep_times;
1022 dat_tmp.srate=srate;
1023 dat_tmp.chans=chans;
1024 dat_tmp.eim_bins=eim_bins;
1025 dat_tmp.bindesc=bindesc;
1026 dat_tmp.ep_times=ep_times;
1027 set(gcf,'UserData',dat_tmp);
1028
1029 for a=get(gcf,'children')',
1030 f=fieldnames(set(a));
1031 for b=1:length(f),
1032 if strcmpi(f{b},'Callback')
1033 set(a,'enable','on');
1034 break;
1035 end
1036 end
1037 end
1038 end
1039 elseif strcmpi(command_str,'create ERPimage') || strcmpi(command_str,'Plot r'),
1040
1041
1042 in_fname=get(h_in_fname,'string');
1043 in_fname2=get(dat_tmp.h_in_fname2,'string');
1044 if strcmpi(in_fname2,'None') || isempty(in_fname2) || strcmpi(in_fname2,'Primary File'),
1045 in_fname2=in_fname;
1046 end
1047 chan=get(h_chan,'string');
1048 chn_id=get(h_chan,'value');
1049 sort_vars=get(h_sort_var,'string');
1050 svar_id=get(h_sort_var,'value');
1051
1052 bins=get(h_bins,'string');
1053 if isempty(bins)
1054 errordlg('You need to select some primary bins or enter "All".','Create ERPimage Error','on');
1055 return;
1056 end
1057 if strcmpi(bins,'All')
1058 bins=[];
1059 n_trials=length(dat_tmp.ep_info);
1060 else
1061 bins=str2num(bins);
1062
1063 n_trials=0;
1064 for a=1:length(dat_tmp.ep_info),
1065 n_bins=length(dat_tmp.ep_info(a).eventtype);
1066 ep_bins=zeros(1,n_bins);
1067 for b=1:n_bins,
1068 ep_bins(b)=str2num(dat_tmp.ep_info(a).eventtype{b}(4:end));
1069 end
1070 if ~isempty(intersect(bins,ep_bins)),
1071 n_trials=n_trials+1;
1072 end
1073 end
1074 end
1075 if n_trials==0,
1076 errordlg('No trials fall into selected bins.','Create ERPimage Error','on');
1077 return
1078 else
1079 fprintf('\n%d trials fall into primary ERPimage''s selected bins.\n\n',n_trials);
1080
1081
1082 ei_title=get(h_title,'String');
1083 if strcmpi(ei_title,'Default'),
1084 ei_title=[];
1085 end
1086
1087 limits=str2num(get(h_timerange,'string'));
1088
1089 if strcmpi(command_str,'Plot r'),
1090 r_figid=str2num(get(h_r_figid,'string'));
1091
1092 plot_eimcorr(sort_vars{svar_id},'in_fname',in_fname,'title',ei_title, ...
1093 'bins',bins,'limits',limits,'fig_id',r_figid);
1094
1095
1096
1097 hist=sprintf('plot_eimcorr(''%s'',''in_fname'',''%s''',sort_vars{svar_id},in_fname);
1098 n_arg=3;
1099 arg{1}='bins';
1100 val{1}=bins;
1101 arg{2}='limits';
1102 val{2}=limits;
1103 arg{3}='fig_id';
1104 val{3}=r_figid;
1105 for hloop=1:n_arg,
1106 if ~isempty(val{hloop})
1107 hist=[hist ',''' arg{hloop} ''',[' num2str(val{hloop}) ']'];
1108 end
1109 end
1110 if ~isempty(ei_title),
1111 hist=[hist ',''title'',''' ei_title ''''];
1112 end
1113 hist=[hist ');'];
1114
1115 if isempty(MK_HIST)
1116 MK_HIST{1}=hist;
1117 else
1118 MK_HIST{length(MK_HIST)+1}=hist;
1119 end
1120 else
1121
1122
1123
1124 limits=[limits str2num(get(h_erprange,'string'))];
1125
1126 caxis=str2num(get(h_eimrange,'string'));
1127
1128 awidth=str2num(get(h_avewidth,'string'));
1129
1130 erps=get(h_erps,'Value')-1;
1131 if ~erps,
1132 erps='off';
1133 end
1134
1135 if get(h_plotsvar,'Value'),
1136 pltsvar='on';
1137 else
1138 pltsvar='off';
1139 end
1140
1141 if get(h_alignsvar,'Value'),
1142 alignsvar=[',''align'',0'];
1143 else
1144 alignsvar=[];
1145 end
1146 if get(h_plothead,'Value'),
1147 topo='on';
1148 else
1149 topo='off';
1150 end
1151
1152 figid=get(h_figid,'String');
1153 if strcmpi(figid,'New Window')
1154 figid=0;
1155 else
1156 figid=str2num(figid);
1157 end
1158
1159 if get(h_splithalf,'Value'),
1160 split='on';
1161 else
1162 split='off';
1163 end
1164
1165 svar_lim=str2num(get(dat_tmp.h_sortvarrange,'string'));
1166
1167 decimate=str2num(get(h_decimate,'string'));
1168
1169 marktrials=str2num(get(h_marktrials,'string'));
1170 marktimes=str2num(get(h_marktimes,'string'));
1171
1172 other=get(h_other,'string');
1173 if ~isempty(other) && (other(1)~=','),
1174 other=[',' other];
1175 end
1176
1177 cmpr_chans=get(h_cmprchan,'string');
1178 cmpr_chan=cmpr_chans{get(h_cmprchan,'value')};
1179 cmpr_bins=get(h_bins2,'string');
1180 if isempty(cmpr_bins),
1181 errordlg('You need to select some secondary bins, enter "All", or enter "None".','Create ERPimage Error','on');
1182 return;
1183 end
1184 if ~strcmpi(cmpr_chan,'None') || ...
1185 ~strcmpi(cmpr_bins,'None') || ...
1186 ~strcmpi(in_fname,in_fname2),
1187
1188
1189 cmpr_bin=str2num(cmpr_bins);
1190
1191 cmnd=['plot_erpimages(bins,cmpr_bin,chan,cmpr_chan,in_fname,in_fname2,sort_vars{svar_id},' ...
1192 '''stdev'',awidth,' ...
1193 '''fig_id'',figid,' ...
1194 '''title'',ei_title,''timelimits'',limits(1:2),''decfactor'',' ...
1195 'decimate,''marktrials'',marktrials,''marktimes'',marktimes,' ...
1196 '''erplimits'',str2num(get(h_erprange,''string'')),''topos'',topo,''showsortvar'',pltsvar,' ...
1197 '''cbarlimits'',caxis,''sortvarlimits'',svar_lim' other ');'];
1198
1199 if ~isempty(alignsvar),
1200 fprintf('\n****** Warning ******\n"Align to Sorting Variable" option not yet implemented for comparing two channels.\n');
1201 fprintf('It will be ignored (Sorry).\n\n');
1202 end
1203
1204 if ~isempty(other),
1205 fprintf('\n****** Warning ******\nThe only "Other:"');
1206 fprintf(' arguments currently supported when comparing two channels and/or bins are:\n');
1207 fprintf(' img_trialax_label, img_trialax_ticks, erpgrid, renorm, rmerp, baseline, filt, erpdiflimits,verblevel,img1_title,img2_title\n');
1208 fprintf('Any other optional arguments will cause an error.\n');
1209 fprintf('Type ">> help plot_erpimages" for more info about these options.\n');
1210 end
1211 else
1212 cmnd=['plot_erpimageMK(chan,sort_vars{svar_id},''in_fname'',in_fname,''avewidth'',awidth,''bins'',bins,' ...
1213 '''fig_id'',figid,''erp'',erps,''plot_sort_var'',pltsvar,''evenodd'',split,' ...
1214 '''title'',ei_title,''limits'',limits,''decimate'',decimate,''mark_trials'',marktrials,''mark_times'',' ...
1215 'marktimes,''caxis'',caxis,''topo'',topo,''sortvar_limits'',svar_lim' alignsvar other ');'];
1216 end
1217 try
1218 eval(cmnd);
1219 catch
1220 err=lasterror;
1221 errordlg(err.message,'Create ERPimage Error','on');
1222 end
1223
1224
1225
1226 if ~strcmpi(cmpr_chan,'None'),
1227 if isempty(bins)
1228 prnt_bins1='[]';
1229 prnt_bins2='[]';
1230 else
1231 prnt_bins1=['[' num2str(bins) ']'];
1232 prnt_bins2=['[' num2str(cmpr_bins) ']'];
1233 end
1234 hist=sprintf('plot_erpimages(%s,%s,''%s'',''%s'',''%s'',''%s'',''%s'',''stdev'',%f',prnt_bins1,prnt_bins2,chan,cmpr_chan,in_fname,in_fname2,sort_vars{svar_id},awidth);
1235 n_arg=6;
1236 arg=cell(n_arg);
1237 val=cell(n_arg);
1238 arg{1}='timelimits';
1239 val{1}=limits(1:2);
1240 arg{2}='marktrials';
1241 val{2}=marktrials;
1242 arg{3}='marktimes';
1243 val{3}=marktimes;
1244 arg{4}='cbarlimits';
1245 val{4}=caxis;
1246 arg{5}='sortvarlimits';
1247 val{5}=svar_lim;
1248 arg{6}='erplimits';
1249 val{6}=str2num(get(h_erprange,'string'));
1250 for hloop=1:n_arg,
1251 if ~isempty(val{hloop})
1252 hist=[hist ',''' arg{hloop} ''',[' num2str(val{hloop}) ']'];
1253 end
1254 end
1255 hist=[hist sprintf(',''fig_id'',%d,''showsortvar'',''%s'',',figid,pltsvar)];
1256 hist=[hist sprintf('''decfactor'',%d,''topos'',''%s''',decimate,topo)];
1257 if ~isempty(ei_title)
1258 hist=[hist sprintf(',''title'',''%s''',ei_title)];
1259 end
1260 hist=[hist alignsvar other ');'];
1261 else
1262 hist=sprintf('plot_erpimageMK(''%s'',''%s'',''in_fname'',''%s'',''avewidth'',%f',chan,sort_vars{svar_id},in_fname,awidth);
1263 n_arg=6;
1264 arg=cell(n_arg);
1265 val=cell(n_arg);
1266 arg{1}='bins';
1267 val{1}=bins;
1268 arg{2}='limits';
1269 val{2}=limits;
1270 arg{3}='mark_trials';
1271 val{3}=marktrials;
1272 arg{4}='mark_times';
1273 val{4}=marktimes;
1274 arg{5}='caxis';
1275 val{5}=caxis;
1276 arg{6}='sortvar_limits';
1277 val{6}=svar_lim;
1278 for hloop=1:n_arg,
1279 if ~isempty(val{hloop})
1280 hist=[hist ',''' arg{hloop} ''',[' num2str(val{hloop}) ']'];
1281 end
1282 end
1283 hist=[hist sprintf(',''fig_id'',%d,''erp'',%d,''plot_sort_var'',''%s'',''evenodd'',''%s''',figid,erps,pltsvar,split)];
1284 hist=[hist sprintf(',''decimate'',%d,''topo'',''%s''',decimate,topo)];
1285 if ~isempty(ei_title)
1286 hist=[hist sprintf(',''title'',''%s''',ei_title)];
1287 end
1288 hist=[hist alignsvar other ');'];
1289 end
1290
1291
1292 if isempty(MK_HIST)
1293 MK_HIST{1}=hist;
1294 else
1295 MK_HIST{length(MK_HIST)+1}=hist;
1296 end
1297 end
1298 end
1299 elseif strcmpi(command_str,'check bins')
1300
1301
1302
1303 dat_tmp=get(h_fig,'UserData');
1304 got_it=0;
1305 req_bins=get(h_bins,'string');
1306 if isempty(req_bins),
1307 req_bins_num=[];
1308 elseif strcmpi(req_bins,'All'),
1309 req_bins_num=dat_tmp.eim_bins;
1310 else
1311 req_bins_num=str2num(req_bins);
1312 no_got=setdiff(req_bins_num,dat_tmp.eim_bins);
1313 if ~isempty(no_got),
1314 errordlg(['Bin(s) ' num2str(no_got) ' is/are not in memory'],'Bin Selection Error','on');
1315 return
1316 end
1317 end
1318
1319
1320 req_bins2=get(h_bins2,'string');
1321 cmpr_bins=0;
1322 bins2_none=1;
1323 if ~isempty(req_bins2) && ~strcmpi(req_bins2,'None'),
1324 bins2_none=0;
1325 if strcmpi(req_bins2,'All'),
1326 req_bins_num2=dat_tmp.eim_bins2;
1327 else
1328 req_bins_num2=str2num(req_bins2);
1329 end
1330 no_got=setdiff(req_bins_num2,dat_tmp.eim_bins2);
1331 if ~isempty(no_got),
1332 errordlg(['Bin(s) ' num2str(no_got) ' is/are not in memory'],'Bin Selection Error','on');
1333 return
1334 end
1335 overlap=intersect(req_bins_num2,req_bins_num);
1336 if length(overlap)~=length(req_bins_num2),
1337 cmpr_bins=1;
1338 end
1339 else
1340 overlap=[];
1341 end
1342
1343
1344 chan_str=get(dat_tmp.h_cmprchan,'string');
1345 chan2=chan_str{get(dat_tmp.h_cmprchan,'value')};
1346 cmpr_chan=0;
1347 chan2_none=1;
1348 if ~strcmpi(chan2,'None')
1349 chan2_none=0;
1350 end
1351 if ~strcmpi(chan2,get(dat_tmp.h_chan,'string')) && ~strcmpi(chan2,'None'),
1352 cmpr_chan=1;
1353 end
1354
1355
1356 infile2=get(dat_tmp.h_in_fname2,'string');
1357 cmpr_file=0;
1358 file2_none=1;
1359 if ~strcmpi(infile2,'None'),
1360 file2_none=0;
1361 end
1362 if ~strcmpi(infile2,'None') && ~strcmpi(infile2,get(dat_tmp.h_in_fname,'string')) ...
1363 && ~strcmpi(infile2,'Primary File'),
1364 cmpr_file=1;
1365 end
1366
1367
1368
1369 if ~cmpr_file && ~cmpr_chan && ~cmpr_bins,
1370 if ~(file2_none && chan2_none && bins2_none),
1371 errordlg('Data in "Basic Parameters" and "Compare ERPimages" are exactly the same. This makes no sense.','Compare ERPimages Error','on');
1372 return
1373 end
1374 end
1375
1376
1377 if file2_none && (cmpr_chan || cmpr_bins)
1378
1379 infile2='Primary File';
1380 set(dat_tmp.h_in_fname2,'string',infile2);
1381 dat_tmp.eim_bins2=dat_tmp.eim_bins;
1382 dat_tmp.bindesc2=dat_tmp.bindesc;
1383 end
1384
1385 if chan2_none,
1386 if cmpr_file,
1387
1388 set(dat_tmp.h_cmprchan,'value',1);
1389 elseif cmpr_bins,
1390
1391 chans2ndry=get(dat_tmp.h_cmprchan,'string');
1392 val=0;
1393 for a=1:length(chans2ndry),
1394 if strcmpi(chans2ndry{a},get(dat_tmp.h_chan,'string')),
1395 val=a;
1396 break;
1397 end
1398 end
1399 set(dat_tmp.h_cmprchan,'value',val);
1400 end
1401 end
1402
1403 if bins2_none && ~isempty(req_bins2),
1404 if cmpr_file,
1405 set(dat_tmp.h_bins2,'string','All');
1406 elseif cmpr_chan
1407
1408 set(dat_tmp.h_bins2,'string',req_bins);
1409 end
1410 end
1411
1412 if cmpr_bins,
1413
1414 if ~isempty(overlap) && ~cmpr_file,
1415
1416
1417 if cmpr_chan,
1418 errordlg('You can''t compare two channels from the same file using two somewhat overlapping sets of bins.','Bin Selection Error','on');
1419 return
1420 else
1421 errordlg(['Bin(s) ' num2str(overlap) ' cannot be both in "Basic Parameters" and "Compare ERPimages" sets of bins.'],'Bin Selection Error','on');
1422 return
1423 end
1424 end
1425 end
1426
1427 elseif strcmpi(command_str,'check chan')
1428
1429
1430 dat_tmp=get(h_fig,'UserData');
1431 got_it=0;
1432 req_chan=get(h_chan,'string');
1433
1434 non_space=find(req_chan~=32);
1435 req_chan=req_chan(non_space);
1436 set(h_chan,'string',req_chan);
1437
1438 for a=1:length(dat_tmp.chans),
1439 if strcmpi(req_chan,dat_tmp.chans{a}),
1440 got_it=1;
1441 break;
1442 end
1443 end
1444
1445 if ~got_it,
1446 h_efig = errordlg(['Channel "' req_chan '" is not in memory'],'Channel Selection Error','on');
1447
1448 set(h_chan,'string',dat_tmp.crnt_chan);
1449 else
1450
1451 old_chan=findobj(h_topo,'tag',str2lowcase(strtok(dat_tmp.crnt_chan)));
1452 set(old_chan,'color','k','markersize',dat_tmp.markersize);
1453
1454
1455 new_chan=findobj(h_topo,'tag',str2lowcase(strtok(req_chan)));
1456 set(new_chan,'color','r','markersize',round(dat_tmp.markersize*1.25));
1457 dat_tmp.crnt_chan=req_chan;
1458 set(gcf,'userdata',dat_tmp);
1459 end
1460 elseif strcmpi(command_str,'check limits')
1461
1462
1463
1464 x_lim=str2num(get(h_timerange,'String'));
1465 if isempty(dat_tmp.ep_times)
1466 errordlg('Load data first','Time range selection error','on');
1467 return
1468 elseif isempty(x_lim)
1469
1470 set(h_timerange,'String',num2str([dat_tmp.ep_times(1) dat_tmp.ep_times(end)]));
1471 elseif (length(x_lim)>2) || (length(x_lim)<2)
1472 errordlg('Time range needs two numbers, the maximum and minimum time in msec (e.g., -100 900). Resetting to default.','Time range selection error','on');
1473 set(h_timerange,'String',num2str([dat_tmp.ep_times(1) dat_tmp.ep_times(end)]));
1474 elseif x_lim(1)<dat_tmp.ep_times(1),
1475 errordlg([num2str(x_lim(1)) ' is too low. Minimum time possible is ' num2str(dat_tmp.ep_times(1))],'Time range selection error','on');
1476 return
1477 elseif x_lim(2)>dat_tmp.ep_times(end)
1478 errordlg([num2str(x_lim(2)) ' is too high. Maximum time possible is ' num2str(dat_tmp.ep_times(end))],'Time range selection error','on');
1479 return
1480 end
1481
1482
1483 x_lim=str2num(get(h_erprange,'String'));
1484 if isempty(x_lim),
1485 set(h_erprange,'String','Default');
1486 else
1487 if (length(x_lim)>2) || (length(x_lim)<2)
1488 errordlg('ERP range needs two numbers, the minimum and maximum voltage in uV (e.g., -8 8). Resetting to default.','ERP range selection error','on');
1489 set(h_erprange,'String','Default');
1490 elseif x_lim(2)<x_lim(1)
1491 errordlg('ERP range maximum is less than ERP range mininum. Reversing their order.','ERP range selection error','on');
1492 set(h_erprange,'String',[num2str(x_lim(2)) ' ' num2str(x_lim(1))]);
1493 end
1494 end
1495
1496
1497 x_lim=str2num(get(h_eimrange,'String'));
1498 if isempty(x_lim),
1499 set(h_eimrange,'String','Default');
1500 else
1501 if (length(x_lim)>2) || (length(x_lim)<2)
1502 errordlg('ERPimage uV range needs two numbers, the minimum and maximum voltage in uV (e.g., -8 8). Resetting to default.','ERPimage uV range selection error','on');
1503 set(h_eimrange,'String','Default');
1504 elseif x_lim(2)<x_lim(1)
1505 errordlg('ERPimage uV range maximum is less than ERPimage uV range mininum. Reversing their order.','ERPimage uV range selection error','on');
1506 set(h_eimrange,'String',[num2str(x_lim(2)) ' ' num2str(x_lim(1))]);
1507 end
1508 end
1509
1510
1511 sv_lim=str2num(get(dat_tmp.h_sortvarrange,'String'));
1512 if isempty(sv_lim),
1513 set(dat_tmp.h_sortvarrange,'String','Default');
1514 else
1515 if (length(sv_lim)>2) || (length(sv_lim)<2)
1516 errordlg('Sorting variable range needs two numbers, the minimum and maximum value of the sorting variable to image. Resetting to default.','Sort var range selection error','on');
1517 set(dat_tmp.h_sortvarrange,'String','Default');
1518 elseif sv_lim(2)<sv_lim(1)
1519 errordlg('Sorting variable range maximum is less than sorting variable range mininum. Reversing their order.','Sort var range selection error','on');
1520 set(dat_tmp.h_sortvarrange,'String',[num2str(sv_lim(2)) ' ' num2str(sv_lim(1))]);
1521 end
1522 end
1523 elseif strcmpi(command_str,'check r_figid')
1524
1525
1526 r_figid=str2num(get(h_r_figid,'string'));
1527 if isempty(r_figid)
1528 if ~strcmpi(get(h_r_figid,'string'),'New')
1529 warndlg('Figure number for "Plot r" must be an integer greater than 0 or "New".','Plot r Error');
1530 set(h_r_figid,'String','New');
1531 end
1532 elseif r_figid<1
1533 warndlg('Figure number for "Plot r" must be an integer greater than 0 or "New".','Plot r Error');
1534 set(h_r_figid,'String','New');
1535 end
1536 elseif strcmpi(command_str,'write_hist')
1537
1538
1539 [filename, pathname] = uiputfile('matlabMK_hist.m','Entire desired filename for command history');
1540 if filename,
1541 fid=fopen([pathname filename],'w');
1542 for z=1:length(MK_HIST),
1543 fprintf(fid,'%s\n',MK_HIST{z});
1544 end
1545 fclose(fid);
1546 end
1547 elseif strcmpi(command_str,'update contrast file')
1548
1549
1550 dat_tmp=get(h_fig,'UserData');
1551 infile2=get(dat_tmp.h_in_fname2,'string');
1552 if strcmpi(infile2,'None') || strcmpi(infile2,'Primary File'),
1553 chans=dat_tmp.chans;
1554 chans{length(chans)+1}='None';
1555 set(dat_tmp.h_cmprchan,'string',chans);
1556 set(dat_tmp.h_cmprchan,'value',length(chans));
1557
1558 set(dat_tmp.h_bins2,'string','None');
1559 dat_tmp.eim_bins2=dat_tmp.eim_bins;
1560
1561 dat_tmp.bindesc2=dat_tmp.bindesc;
1562 else
1563 try
1564 load(infile2,'chans','-MAT');
1565 catch
1566 err=lasterror;
1567 h_efig = errordlg(err.message,'Secondary Input File Error','on');
1568 set(dat_tmp.h_in_fname2,'string','None');
1569 gui_erpimage('update contrast file');
1570 end
1571 chans{length(chans)+1}='None';
1572 set(dat_tmp.h_cmprchan,'string',chans);
1573 set(dat_tmp.h_cmprchan,'value',1);
1574 set(dat_tmp.h_splithalf,'value',0);
1575
1576 set(dat_tmp.h_bins2,'string','All');
1577 load(infile2,'eim_bins','-MAT');
1578 dat_tmp.eim_bins2=eim_bins;
1579
1580 load(infile2,'bindesc','-MAT');
1581 dat_tmp.bindesc2=bindesc;
1582 end
1583
1584 set(h_fig,'UserData',dat_tmp);
1585 elseif strcmpi(command_str,'deactivate compare')
1586
1587
1588 tmp=get(gcf,'userdata');
1589
1590
1591 set(tmp.h_bins2,'string','None');
1592 set(tmp.h_in_fname2,'string','None');
1593 set(tmp.h_cmprchan,'value',length(get(tmp.h_cmprchan,'string')));
1594
1595 set(gcf,'userdata',tmp);
1596 end
1597
1598
1599
1600 function lowcase=str2lowcase(str)
1601
1602 n=length(str);
1603 lowcase=zeros(1,n);
1604 for a=1:n,
1605 if (str(a)>=65) && (str(a)<=90)
1606 lowcase(a)=str(a)+32;
1607 else
1608 lowcase(a)=str(a);
1609 end
1610 end
1611 lowcase=char(lowcase);