Home > matlabmk > gui_eim_corr.m

gui_eim_corr

PURPOSE ^

gui_eim_corr() - Open a GUI for exploring the correlation between EEG and

SYNOPSIS ^

function gui_eim_corr(cmnd_str,fig_id,r,rho,n,chanlocs,ep_times,plt_times,sort_var,fig_title)

DESCRIPTION ^

 gui_eim_corr() - Open a GUI for exploring the correlation between EEG and
                  ERPimage-able variables (e.g., reaction time).  Designed
                  to be called by gui_erpimage.m.

 Usage:
  >> gui_eim_corr(cmnd_str,fig_id,r,rho,n,chanlocs,ep_times,plt_times,sort_var,fig_title)


 Required Input:
   cmnd_str   - One of the following strings:
                   1. 'initialize'(intialize the GUI)
                   2. 'time jump'(change the time point whose topography
                       is visualized)
                   3. 'back one'(go back one time point)
                   4. 'forward one'(go forward one time point)
                   5. 'back'(animate topography going backwards in time)
                   6. 'forward'(animate topography going forwards in time)
                   7. 'change stat'(change the correlation statistic that is being visualized)
                   8. 'new time limits'(change the x-axis range on the
                       correlation x time axis)
                   9. 'new statistic limits'(change the y-axis range on the
                       correlation x time axis)

 Optional Inputs (you may use this function with 1, 2, or all 10 arguments):
  fig_id      - The id number of the figure in which the GUI will be
                 created.  If empty or not specified a new figure will be created.
  r           - Matrix of the Pearson's r between the EEG at each channel
                 and the variable of interest.
  rho         - Matrix of the Spearman's rho (i.e., rank correlation) between 
                 the EEG at each channel and the variable of interest.
  n           - The number of trials (necessary for computing t-scores).
  chanlocs    - An EEGLAB chanlocs channel location struct array.
  ep_times    - The vector of times that each time point corresponds to.
  plt_times   - Two element vector specifiying the y-axis min and max time
                 point on the correlation x time axis)
  sort_var    - The name of the ERPimage-able variable whose correlation
                 with the EEG is being visualized (e.g., 'rtmsec').
  fig_title   - The title for the correlation x time axis


 Notes:
  -You can't open more than one gui_eim_corr at time, but you can not animate more 
  than one gui_eim_corr at a time.  Starting a second animation will
  pause the first animation.  The first animation will re-start once the
  second animation stops.

  -Matlab editor gives warning the calling axes.m without an output
  argument slows down the function.  However, the only time I uses axes
  without an output argument is for making a particular axis the current
  axes.  It's not legal to use axes with an ouput argument for that
  purpose.

  -r (and rho) are converted into t-scores via the following formula
  (Zarr [1999] Biostatistical Analysis):
     t=r/((1-r^2)/(n-2))
  t-scores are derived from the null hypothesis that r (or rho) is 0.
  They are useful to visualize when correlations at multiple channels are
  very extreme (near +-1) as at that range small differences in
  correlation can correspond to large differences in significance.
  However the t-scores should not be interpreted a p-values since no
  attempt is made to control for multiple comparisons or the
  non-independence of epochs.

 Author:
 David Groppe
 Kutaslab, 9/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function gui_eim_corr(cmnd_str,fig_id,r,rho,n,chanlocs,ep_times,plt_times,sort_var,fig_title)
0002 % gui_eim_corr() - Open a GUI for exploring the correlation between EEG and
0003 %                  ERPimage-able variables (e.g., reaction time).  Designed
0004 %                  to be called by gui_erpimage.m.
0005 %
0006 % Usage:
0007 %  >> gui_eim_corr(cmnd_str,fig_id,r,rho,n,chanlocs,ep_times,plt_times,sort_var,fig_title)
0008 %
0009 %
0010 % Required Input:
0011 %   cmnd_str   - One of the following strings:
0012 %                   1. 'initialize'(intialize the GUI)
0013 %                   2. 'time jump'(change the time point whose topography
0014 %                       is visualized)
0015 %                   3. 'back one'(go back one time point)
0016 %                   4. 'forward one'(go forward one time point)
0017 %                   5. 'back'(animate topography going backwards in time)
0018 %                   6. 'forward'(animate topography going forwards in time)
0019 %                   7. 'change stat'(change the correlation statistic that is being visualized)
0020 %                   8. 'new time limits'(change the x-axis range on the
0021 %                       correlation x time axis)
0022 %                   9. 'new statistic limits'(change the y-axis range on the
0023 %                       correlation x time axis)
0024 %
0025 % Optional Inputs (you may use this function with 1, 2, or all 10 arguments):
0026 %  fig_id      - The id number of the figure in which the GUI will be
0027 %                 created.  If empty or not specified a new figure will be created.
0028 %  r           - Matrix of the Pearson's r between the EEG at each channel
0029 %                 and the variable of interest.
0030 %  rho         - Matrix of the Spearman's rho (i.e., rank correlation) between
0031 %                 the EEG at each channel and the variable of interest.
0032 %  n           - The number of trials (necessary for computing t-scores).
0033 %  chanlocs    - An EEGLAB chanlocs channel location struct array.
0034 %  ep_times    - The vector of times that each time point corresponds to.
0035 %  plt_times   - Two element vector specifiying the y-axis min and max time
0036 %                 point on the correlation x time axis)
0037 %  sort_var    - The name of the ERPimage-able variable whose correlation
0038 %                 with the EEG is being visualized (e.g., 'rtmsec').
0039 %  fig_title   - The title for the correlation x time axis
0040 %
0041 %
0042 % Notes:
0043 %  -You can't open more than one gui_eim_corr at time, but you can not animate more
0044 %  than one gui_eim_corr at a time.  Starting a second animation will
0045 %  pause the first animation.  The first animation will re-start once the
0046 %  second animation stops.
0047 %
0048 %  -Matlab editor gives warning the calling axes.m without an output
0049 %  argument slows down the function.  However, the only time I uses axes
0050 %  without an output argument is for making a particular axis the current
0051 %  axes.  It's not legal to use axes with an ouput argument for that
0052 %  purpose.
0053 %
0054 %  -r (and rho) are converted into t-scores via the following formula
0055 %  (Zarr [1999] Biostatistical Analysis):
0056 %     t=r/((1-r^2)/(n-2))
0057 %  t-scores are derived from the null hypothesis that r (or rho) is 0.
0058 %  They are useful to visualize when correlations at multiple channels are
0059 %  very extreme (near +-1) as at that range small differences in
0060 %  correlation can correspond to large differences in significance.
0061 %  However the t-scores should not be interpreted a p-values since no
0062 %  attempt is made to control for multiple comparisons or the
0063 %  non-independence of epochs.
0064 %
0065 % Author:
0066 % David Groppe
0067 % Kutaslab, 9/2009
0068 
0069 %Future Improvements:
0070 %-Make it possible to animate more than one GUI at a time?
0071 %
0072 %-Make it possible to change topo color limits?  I don't know how do-able
0073 %this is since values that exceed topo color limits are impossible to
0074 %distinguish from values that are at the topo color limits.
0075 %
0076 %-Make it possible to click on correlation x time plot during an animation
0077 %to change the time?
0078 %
0079 %-Make it possible to right-click on axis to get them to pop-up in a new
0080 %figure?
0081 %
0082 %-Make color scheme same as EEGLAB GUIs (see variabl frm_col)?
0083 %
0084 
0085 if nargin==1,
0086     fig_id=[];
0087 elseif (nargin~=10) && (nargin~=2),
0088    error('plot_eimcorr.m requires 1,2, or 10 arguments.'); 
0089 end
0090 
0091 if ~strcmp(cmnd_str,'initialize')
0092     if isempty(fig_id),
0093         fig_id=gcf;
0094     end
0095     if ~strcmp(get(fig_id,'tag'),'gui_corr')
0096         % If the current figure does not have the right
0097         % tag, find the one that does.
0098         h_figs = get(0,'children');
0099         fig_id = findobj(h_figs,'flat',...
0100             'tag','gui_corr');
0101         if isempty(fig_id),
0102             % If gui_erpimage does not exist
0103             % initialize it. Then run the command string
0104             % that was originally requested.
0105             gui_corr('initialize');
0106             gui_corr(cmnd_str);
0107             return;
0108         end
0109     end
0110     
0111     % At this point we know that h_fig is the handle
0112     % to a figure containing the GUI of interest to
0113     % this function (it's possible that more than one of these
0114     % GUI figures is open).  Therefore we can use this figure
0115     % handle to cut down on the number of objects
0116     % that need to be searched for tag names as follows:
0117     dat=get(gcf,'userdata');
0118 end
0119 
0120 % INITIALIZE THE GUI SECTION.
0121 if strcmp(cmnd_str,'initialize')
0122     % Creates a new GUI (even if one already exists)
0123     if isempty(fig_id),
0124         dat.fig_id=figure;
0125     else
0126         dat.fig_id=fig_id;
0127         figure(dat.fig_id);
0128         clf
0129     end
0130     set(dat.fig_id,'name','Correlation GUI','tag','gui_corr', ...
0131         'MenuBar','none','position',[139 282 690 420]);
0132     
0133     %attach data to figure
0134     dat.r=r;
0135     dat.rho=rho;
0136     dat.t_r=r./sqrt( (1-(r.*r))/(n-2)); 
0137     dat.t_rho=rho./sqrt( (1-(rho.*rho))/(n-2));
0138     dat.n=n;
0139     dat.showing=r;
0140     dat.chanlocs=chanlocs;
0141     dat.times=ep_times;
0142     dat.sort_var=sort_var;
0143  
0144   
0145     %
0146     %%%%%%%%%%%%%%%%%%%%%%  Time x Correlation Axes %%%%%%%%%%%%%%%%%%%%%%%%
0147     %
0148     
0149     frm_col=[1 1 1]*.702; %?? fix later
0150     uipanel(dat.fig_id,...
0151         'Units','normalized', ...
0152         'Position',[ 0 0.13 .72 0.87 ],...
0153         'shadowcolor','k', ...
0154         'highlightcolor',frm_col, ...
0155         'foregroundcolor',frm_col, ...
0156         'backgroundcolor',frm_col);
0157     
0158     dat.h_time=axes('position',[0.1 .24 .6 .67]);
0159     dat.start_pt=find_tpt(plt_times(1),ep_times);
0160     dat.end_pt=find_tpt(plt_times(2),ep_times);
0161     plotted_pts=dat.start_pt:dat.end_pt;
0162     plotted_times=ep_times(dat.start_pt:dat.end_pt);
0163     [absmx mx_tpt]=max(max(abs(r(:,dat.start_pt:dat.end_pt))));
0164     plot([plotted_times(1) plotted_times(end)],[0 0],'k'); % corr=0 line
0165     hold on;
0166     dat.h_t0line=plot([0 0],[-1 1]*absmx,'k'); % time=0 line
0167     set(dat.h_time,'ygrid','on');
0168     dat.h_showing=plot(dat.times,r');
0169     dat.h_showing=dat.h_showing;
0170     axis tight;
0171     v=axis;
0172     axis([plotted_times(1) plotted_times(end) v(3:4)]);
0173     dat.h_line=plot([1 1]*plotted_times(mx_tpt),v(3:4),'k');
0174     set(dat.h_line,'linewidth',2);
0175     h=xlabel('Time (msec)');
0176     set(h,'fontsize',14,'fontunits','normalized');
0177     h=ylabel(['r (EEG vs. ' sort_var ')']);
0178     dat.h_time_ylab=h;
0179     set(h,'fontsize',14,'fontunits','normalized');
0180     h=title(fig_title);
0181     set(h,'fontsize',18,'fontunits','normalized');
0182     bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0183         'dat=get(gcf, ''userdata'');' ...
0184         'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
0185         'set(dat.h_line,''XData'',[1 1]*dat.times(new_tpt));' ...
0186         'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
0187         'axes(dat.h_topo);' ...
0188         'topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,''maplimits'',[-1 1]*dat.absmx);' ...
0189         'drawnow;' ...
0190         'set(dat.fig_id,''userdata'',dat);' ...
0191         'clear latpoint dattmp tmppos;' ...
0192         ];
0193     set(dat.h_time,'ButtonDownFcn',bdf_code);
0194     set(dat.h_showing,'ButtonDownFcn',bdf_code);
0195 
0196   
0197     %
0198     %%%%%%%%%%%%%%%%%%%%%% Correlation Topography %%%%%%%%%%%%%%%%%%%%%%%%
0199     %
0200 
0201     % PANEL
0202     uipanel(dat.fig_id,...
0203         'Units','normalized', ...
0204         'Position',[ 0.719 0.13 0.281 0.87 ],...
0205         'shadowcolor','k', ...
0206         'highlightcolor',frm_col, ...
0207         'foregroundcolor',frm_col, ...
0208         'backgroundcolor',frm_col);   
0209     
0210     % TOPOGRAPHY
0211     dat.h_topo=axes('position',[0.66 .39 .42 .42],'box','off');
0212     dat.absmx=absmx;
0213     %dat.topo_time=plotted_times(mx_tpt);
0214     topoplotMK(r(:,plotted_pts(mx_tpt)),chanlocs,'maplimits',[-1 1]*absmx);
0215     %set(dat.h_topo,'color',frm_col); %this doesn't appear to have any effect
0216     %set(dat.fig_id,'color',frm_col); %this doesn't appear to have any effect
0217     
0218     % COLOR BAR
0219     dat.h_cbar=axes('position',[0.77 .86 .2 .06]);
0220     cbar(dat.h_cbar);
0221     absmx=round(absmx*100)/100;
0222     set(gca,'xticklabel',[-absmx 0 absmx]);
0223     h_cbar_title=title('Pearson''s r');
0224     set(h_cbar_title,'fontsize',14);
0225     
0226     %%% TIME POINT TEXT BOX
0227     %STATIC TEXT LABEL
0228     uicontrol(dat.fig_id,...
0229         'Units','normalized', ...
0230         'Position',[ 0.905 0.315 0.07 0.06 ],...
0231         'String','msec',...
0232         'fontsize',14, ...
0233         'fontunits','normalized', ...
0234         'Style','text');
0235     dat.h_topo_time=uicontrol(dat.fig_id,...
0236         'CallBack','gui_eim_corr(''time jump'');',...
0237         'Units','normalized', ...
0238         'Position',[ 0.80 0.31 0.1 0.08 ], ...
0239         'String',num2str(plotted_times(mx_tpt)), ...
0240         'Style','edit', ...
0241         'Enable','on', ...
0242         'ToolTipString','Time point to visualize topographicaly.', ...
0243         'fontsize',14, ...
0244         'fontunits','normalized', ...
0245         'horizontalalignment','center', ...
0246         'BackGroundColor','w', ...
0247         'Tag','topo_time');
0248     
0249     % GO BACK 1 TIME POINT
0250     dat.h_back1=uicontrol(dat.fig_id,...
0251         'CallBack','gui_eim_corr(''back one'');',...
0252         'Units','normalized', ...
0253         'Position',[ 0.81 0.23 0.055 0.07 ],...
0254         'String','<',...
0255         'fontsize',14, ...
0256         'fontunits','normalized', ...
0257         'Tag','back1', ...
0258         'ToolTipString','Show topography at preceding time point.', ...
0259         'Style','pushbutton');
0260     
0261     % GO FORWARD 1 TIME POINT
0262     dat.h_forward1=uicontrol(dat.fig_id,...
0263         'CallBack','gui_eim_corr(''forward one'');',...
0264         'Units','normalized', ...
0265         'Position',[ 0.875 0.23 0.055 0.07 ],...
0266         'String','>', ...
0267         'fontsize',14, ...
0268         'fontunits','normalized', ...
0269         'Tag','forward1', ...
0270         'ToolTipString','Show topography at subsequent time point.', ...
0271         'Style','pushbutton');
0272     
0273     % ANIMATE BACKWARDS IN TIME
0274     dat.h_back=uicontrol(dat.fig_id,...
0275         'CallBack','gui_eim_corr(''back'');',...
0276         'Units','normalized', ...
0277         'Position',[ 0.745 0.23 0.055 0.07 ],...
0278         'String','<<',...
0279         'fontsize',14, ...
0280         'fontunits','normalized', ...
0281         'Tag','back', ...
0282         'interruptible','on', ...
0283         'ToolTipString','Animate topography going backwards in time.', ...
0284         'Style','pushbutton');
0285     
0286     % ANIMATE FORWARDS IN TIME
0287     dat.h_forward=uicontrol(dat.fig_id,...
0288         'CallBack','gui_eim_corr(''forward'');',...
0289         'Units','normalized', ...
0290         'Position',[ 0.94 0.23 0.055 0.07 ],...
0291         'String','>>',...
0292         'fontsize',14, ...
0293         'fontunits','normalized', ...
0294         'Tag','back', ...
0295         'interruptible','on', ...
0296         'ToolTipString','Animate topography going forwards in time.', ...
0297         'Style','pushbutton');
0298     
0299     % STOP ANIMATION
0300     dat.h_stop=uicontrol(dat.fig_id,...
0301         'CallBack','dat=get(gcf,''userdata''); dat.interrupt=1; set(dat.fig_id,''userdata'',dat);',...
0302         'Units','normalized', ...
0303         'Position',[ 0.76 0.15 0.23 0.07 ],...
0304         'String','Stop Animation',...
0305         'fontsize',14, ...
0306         'fontunits','normalized', ...
0307         'Tag','stop', ...
0308         'enable','off', ...
0309         'ToolTipString','Stop topography animation.', ...
0310         'Style','pushbutton');
0311     
0312     
0313     %
0314     %%%%%%%%%%%%%%%%%%%%%% PLOTTING OPTIONS %%%%%%%%%%%%%%%%%%%%%%%%
0315     %
0316     
0317     % PANEL
0318     uipanel(dat.fig_id,...
0319         'Units','normalized', ...
0320         'Position',[ 0 0 1 0.133 ],...
0321         'shadowcolor','k', ...
0322         'highlightcolor',frm_col, ...
0323         'foregroundcolor',frm_col, ...
0324         'backgroundcolor',frm_col);
0325     
0326     %%%% WHICH STAT TO PLOT
0327     stats={'Pearson''s r','t-score of r','Spearman''s rho','t-score of rho'};
0328     % Text
0329     uicontrol(dat.fig_id,...
0330         'Units','normalized', ...
0331         'Position',[ 0.01 0.06 0.2 0.06 ],...
0332         'String','Correlation Statistic',...
0333         'fontsize',12, ...
0334         'ToolTipString','Correlation statistic to plot against time.', ...
0335         'Style','text');
0336     % Create sortvar browse button
0337     dat.h_stat=uicontrol(dat.fig_id,...
0338         'CallBack','gui_eim_corr(''change stat'');',...
0339         'Units','normalized', ...
0340         'Position',[ 0.02 0 0.18 0.07 ],...
0341         'fontsize',12, ...
0342         'String',stats, ...
0343         'Style','popup', ...
0344         'ToolTipString','Correlation statistic to plot across time.', ...
0345         'tag','stat');
0346     
0347     %%% TIME RANGE
0348     %Text
0349     uicontrol(dat.fig_id,...
0350         'Units','normalized', ...
0351         'Position',[ 0.22 0.06 0.24 0.06 ],...
0352         'String','Time Range (Min Max):',...
0353         'fontsize',12, ...
0354         'Style','text');
0355     %Edit Box
0356     dat.h_timerange=uicontrol(dat.fig_id,...
0357         'CallBack','gui_eim_corr(''new time limits'');',...
0358         'Units','normalized', ...
0359         'fontsize',12, ...
0360         'BackGroundColor','w', ...
0361         'Position',[ 0.25 0.017 0.16 0.06 ],...
0362         'String',num2str(plt_times), ...
0363         'Style','edit', ...
0364         'ToolTipString','Miniumum and maximum time on Time x Correlation axis.', ...
0365         'tag','timerange');   
0366       
0367     %%% STATISTIC RANGE BOX
0368     %Text
0369     uicontrol(dat.fig_id,...
0370         'Units','normalized', ...
0371         'Position',[ 0.48 0.06 0.26 0.06 ],...
0372         'String','Statistic Range (Min Max):',...
0373         'HorizontalAlignment','left', ...
0374         'fontsize',12, ...
0375         'Style','text');
0376     %Edit Box
0377     dat.h_statrange=uicontrol(dat.fig_id,...
0378         'CallBack','gui_eim_corr(''new statistic limits'');',...
0379         'Units','normalized', ...
0380         'fontsize',12, ...
0381         'BackGroundColor','w', ...
0382         'Position',[ 0.52 0.017 0.16 0.06 ],...
0383         'String',num2str(round(v(3:4)*100)/100), ...
0384         'ToolTipString','Miniumum and maximum correlation statistic on Time x Correlation axis.', ...
0385         'Style','edit', ...
0386         'tag','statrange');   
0387     
0388     % Button to close GUI
0389     uicontrol(dat.fig_id,...
0390         'CallBack','close(gcf);',...
0391         'Units','normalized', ...
0392         'Position',[ 0.75 0.025 0.11 0.1 ],...
0393         'String','Cancel',...
0394         'fontsize',12, ...
0395         'Tag','cancel', ...
0396         'ToolTipString','Close GUI', ...
0397         'Style','pushbutton');
0398     
0399     dat.help_msg=sprintf(['Hold mouse cursor over a GUI control for an explanation of what it does.\n\n', ...
0400         'Time x Correlation axis visualizes the correlation between EEG and %s simultaneously at all loaded electrodes.  ' ... 
0401         'Each colored line corresponds to a different electrode.\n\nClick on Time x Correlation axis to visualize the scalp topography\n', ...
0402         'of the correlations at that point in time.\n\nClick on electrodes in scalp topography to see electrode name.\n\n', ...
0403         'This GUI was produced by gui_eim_corr.m'],sort_var);
0404     
0405     % Button for help
0406     uicontrol(dat.fig_id,...
0407         'CallBack','dat=get(gcf,''userdata''); helpdlg(dat.help_msg,''ERPimage Correlation GUI Help'');', ...
0408         'Units','normalized', ...
0409         'Position',[ 0.87 0.025 0.11 0.1 ],...
0410         'String','Help',...
0411         'fontsize',12, ...
0412         'Tag','help', ...
0413         'ToolTipString','Click for help', ...
0414         'Style','pushbutton');
0415     dat.interrupt=1;
0416     set(dat.fig_id,'userdata',dat);
0417 elseif strcmpi(cmnd_str,'time jump'),
0418     axes(dat.h_topo);
0419     new_tpt=find_tpt(str2num(get(dat.h_topo_time,'string')), ...
0420         dat.times);
0421     if new_tpt<dat.start_pt,
0422         errordlg('That time is too early.');
0423     elseif new_tpt>dat.end_pt,
0424         errordlg('That time is too late.');
0425     else
0426         topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0427         set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0428         set(dat.h_line,'XData',[1 1]*dat.times(new_tpt));
0429         drawnow;
0430         set(dat.fig_id,'userdata',dat);
0431     end    
0432 elseif strcmpi(cmnd_str,'back one'),
0433     axes(dat.h_topo);
0434     current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
0435         dat.times);
0436     new_tpt=current_tpt-1;
0437     if new_tpt<dat.start_pt,
0438         errordlg('Can''t go back any further.');
0439     else
0440         topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0441         set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0442         set(dat.h_line,'XData',[1 1]*dat.times(new_tpt));
0443         drawnow;
0444         set(dat.fig_id,'userdata',dat);
0445     end
0446 elseif strcmpi(cmnd_str,'forward one'),
0447     axes(dat.h_topo);
0448     current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
0449         dat.times);
0450     new_tpt=current_tpt+1;
0451     if new_tpt>dat.end_pt,
0452         errordlg('Can''t go forward any further.');
0453     else
0454         topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0455         set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0456         set(dat.h_line,'XData',[1 1]*dat.times(new_tpt));
0457         drawnow;
0458         set(dat.fig_id,'userdata',dat);
0459     end
0460 elseif strcmpi(cmnd_str,'back'),
0461     axes(dat.h_topo);
0462     interrupt=0;
0463     dat.interrupt=0;
0464     set(dat.h_stop,'enable','on');
0465     set(dat.h_forward,'enable','off');
0466     set(dat.h_back,'enable','off');
0467     set(dat.fig_id,'userdata',dat);
0468     drawnow;
0469     current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
0470         dat.times);
0471     new_tpt=current_tpt-1;
0472     loop_ct=0;
0473     while (new_tpt>=dat.start_pt) && (interrupt~=1),
0474         axes(dat.h_topo);
0475         topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0476         set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0477         set(dat.h_line,'XData',[1 1]*dat.times(new_tpt));
0478         drawnow;
0479         new_tpt=new_tpt-1;
0480         loop_ct=loop_ct+1;
0481         if loop_ct==5,
0482             loop_ct=0;
0483             new_tmp=get(dat.fig_id,'userdata');
0484             interrupt=new_tmp.interrupt;
0485         end
0486     end
0487     drawnow;
0488     dat.interrupt=0;
0489     new_tpt=new_tpt+1; %undo step that broke loop
0490     set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0491     set(dat.h_stop,'enable','off');
0492     set(dat.h_forward,'enable','on');
0493     set(dat.h_back,'enable','on');
0494     set(dat.fig_id,'userdata',dat);
0495 elseif strcmpi(cmnd_str,'forward'),
0496     axes(dat.h_topo);
0497     interrupt=0;
0498     dat.interrupt=0;
0499     set(dat.h_stop,'enable','on');
0500     set(dat.h_forward,'enable','off');
0501     set(dat.h_back,'enable','off');
0502     set(dat.fig_id,'userdata',dat);
0503     drawnow;
0504     current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
0505         dat.times);
0506     new_tpt=current_tpt+1;
0507     loop_ct=0;
0508     while (new_tpt<=dat.end_pt) && (interrupt~=1),
0509         axes(dat.h_topo);
0510         topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0511         set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0512         set(dat.h_line,'XData',[1 1]*dat.times(new_tpt));
0513         drawnow;
0514         new_tpt=new_tpt+1;
0515         loop_ct=loop_ct+1;
0516         if loop_ct==5,
0517             loop_ct=0;
0518             new_tmp=get(dat.fig_id,'userdata');
0519             interrupt=new_tmp.interrupt;
0520         end
0521     end
0522     drawnow;
0523     dat.interrupt=0;
0524     new_tpt=new_tpt-1; %undo step that broke loop
0525     set(dat.h_topo_time,'string',num2str(dat.times(new_tpt)));
0526     set(dat.h_stop,'enable','off');
0527     set(dat.h_forward,'enable','on');
0528     set(dat.h_back,'enable','on');
0529     set(dat.fig_id,'userdata',dat); 
0530 elseif strcmpi(cmnd_str,'change stat'),
0531     stat=get(dat.h_stat,'value');
0532     switch stat
0533         case 1,
0534             dat.showing=dat.r;
0535             cbar_title='Pearson''s r';
0536             ylab=['r (EEG vs. ' dat.sort_var ')'];
0537         case 2,
0538             dat.showing=dat.t_r;
0539             cbar_title='t-score of r';
0540             ylab=['t of r (EEG vs. ' dat.sort_var ')'];
0541         case 3,
0542             dat.showing=dat.rho;
0543             cbar_title='Spearman''s rho';
0544             ylab=['rho (EEG vs. ' dat.sort_var ')'];
0545         case 4,
0546             dat.showing=dat.t_rho;
0547             cbar_title='t-score of rho';
0548             ylab=['t of rho (EEG vs. ' dat.sort_var ')'];
0549     end
0550     
0551     %redraw time plot
0552     axes(dat.h_time);
0553     delete(dat.h_showing);
0554     delete(dat.h_line);
0555     plotted_times=dat.times(dat.start_pt:dat.end_pt);    
0556     dat.h_showing=plot(dat.times,dat.showing');
0557     r_mx=max(max(dat.showing));
0558     r_mn=min(min(dat.showing));
0559     r_rng=r_mx-r_mn;
0560     r_plt_rng=[r_mn-r_rng*.02 r_mx+r_rng*.02];
0561     r_plt_rng=round(r_plt_rng*100)/100;
0562     axis([plotted_times(1) plotted_times(end) r_plt_rng]); 
0563     set(dat.h_statrange,'string',num2str(r_plt_rng));
0564     set(dat.h_t0line,'YData',r_plt_rng); %adjust time=0 line
0565     current_tpt=find_tpt(str2double(get(dat.h_topo_time,'string')), ...
0566         dat.times);
0567     h_line=plot([1 1]*dat.times(current_tpt),r_plt_rng,'k');
0568     set(h_line,'linewidth',2);
0569     dat.h_line=h_line;
0570     set(dat.h_time_ylab,'string',ylab); %y-label
0571     
0572     bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0573         'dat=get(gcf, ''userdata'');' ...
0574         'new_tpt=find_tpt(tmppos(1,1),dat.times);' ...
0575         'set(dat.h_line,''XData'',[1 1]*dat.times(new_tpt));' ...
0576         'set(dat.h_topo_time,''string'',num2str(dat.times(new_tpt)));' ...
0577         'axes(dat.h_topo);' ...
0578         'topoplotMK(dat.showing(:,new_tpt),dat.chanlocs,''maplimits'',[-1 1]*dat.absmx);' ...
0579         'drawnow;' ...
0580         'set(dat.fig_id,''userdata'',dat);' ...
0581         'clear latpoint dattmp tmppos;' ...
0582         ];
0583     set(dat.h_showing,'ButtonDownFcn',bdf_code);
0584     
0585     
0586     %redraw topo plot
0587     axes(dat.h_topo);
0588     dat.absmx=max(max(abs(dat.showing(:,dat.start_pt:dat.end_pt))));
0589     topoplotMK(dat.showing(:,current_tpt),dat.chanlocs,'maplimits',[-1 1]*dat.absmx);
0590     
0591     %redraw topo color bar
0592     axes(dat.h_cbar);
0593     cla;
0594     cbar(dat.h_cbar);
0595     absmx=round(dat.absmx*100)/100;
0596     set(gca,'xticklabel',[-absmx 0 absmx]);
0597     h_cbar_title=title(cbar_title);
0598     set(h_cbar_title,'fontsize',14);
0599     
0600     set(dat.fig_id,'userdata',dat);
0601 elseif strcmpi(cmnd_str,'new time limits'),
0602     %time limits
0603     plotted_times=dat.times(dat.start_pt:dat.end_pt);
0604     tme_lim=str2num(get(dat.h_timerange,'string'));
0605     if length(tme_lim)~=2,
0606         errordlg('Enter exactly two values for time range (desired Min and Max values).','ERPimage Correlation GUI Error');
0607         set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)])); %reset time limits
0608     elseif tme_lim(2)<tme_lim(1),
0609         errordlg('The second time range value must be greater than the first (enter desired Min then Max).','ERPimage Correlation GUI Error');
0610         set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)])); %reset time limits
0611     elseif (tme_lim(1)<dat.times(1)) || (tme_lim(2)>dat.times(end))
0612         errordlg(sprintf('Time range values must be between %d and %d msec.',dat.times(1),dat.times(end)),'ERPimage Correlation GUI Error');
0613         set(dat.h_timerange,'string',num2str([plotted_times(1) plotted_times(end)])); %reset time limits
0614     else
0615         %change time limits
0616         set(dat.h_time,'xlim',tme_lim);
0617         dat.start_pt=find_tpt(tme_lim(1),dat.times);
0618         dat.end_pt=find_tpt(tme_lim(2),dat.times);
0619         set(dat.fig_id,'userdata',dat);
0620     end
0621 elseif strcmpi(cmnd_str,'new statistic limits'),
0622     %statistic limits
0623     plotted_limits=get(dat.h_time,'ylim');
0624     new_lim=str2num(get(dat.h_statrange,'string'));
0625     if length(new_lim)~=2,
0626         errordlg('Enter exactly two values for statistic range (desired Min and Max values).','ERPimage Correlation GUI Error');
0627         set(dat.h_statrange,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
0628     elseif new_lim(2)<new_lim(1),
0629         errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','ERPimage Correlation GUI Error');
0630         set(dat.h_statrange,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
0631     else
0632         %change time limits
0633         set(dat.h_time,'ylim',new_lim);
0634         set(dat.h_t0line,'YData',new_lim); %adjust time=0 line
0635         set(dat.h_line,'YData',new_lim); %adjust current time pt line
0636     end    
0637 end

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005