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