Home > matlabmk > gui_pow.m

gui_pow

PURPOSE ^

gui_pow() - Open a GUI for visualzing butterfly plots of EEG power spectra

SYNOPSIS ^

function gui_pow(cmnd_str,varargin)

DESCRIPTION ^

 gui_pow() - Open a GUI for visualzing butterfly plots of EEG power spectra 
             and topographies.  t-scores, standard error and root mean 
             square power can also be visualized. Hold mouse cursor over 
             GUI controls for an explanation of what they do.  Click on 
             data traces to visualize the scalp topography at that
             frequency. Click on electrodes in scalp topography to see
             electrode name.  Note, you can open more than one "gui_pow"
             at a time in different windows, but you cannot animate more
             than one gui_pow window at a time.

 Usage:
  >> gui_pow(cmnd_str,varargin);
   or
  >> gui_pow(specGND_or_specGRP,varargin);

 Required Input:
   cmnd_str   - One of the following strings:
                   1.  'initialize'(intialize the GUI)
                   2.  'freq jump'(change the frequency whose topography
                        is visualized)
                   3.  'back one'(go back one frequency)
                   4.  'forward one'(go forward one frequency)
                   5.  'back'(animate topography going backwards in frequency)
                   6.  'forward'(animate topography going forwards in frequency)
                   7.  'change stat'(change the statistic that is being
                        visualized [t-score, standard error, or RMS])
                   8.  'new freq limits'(change the x-axis range on the
                        waveform x frequency axes)
                   9.  'new statistic limitsA'(change the y-axis range on the
                        power x frequency axis--i.e., Axis A)
                   10. 'new statistic limitsB' (change the y-axis range on the
                        t-score/stderr/rms x frequency axis--i.e., Axis B)
                   11. 'change bin' (visualize a different bin)
                   12. 'update dashed lines' (redraws dashed lines
                        representing t-test frequency window)
                   13. 'update critical t' (redraws dashed lines
                        representing t-test critical
                        t-scores)
                   14. 'redraw topo' (redraws topographies)
                   15. 'change test' (change the t-test results being
                        visualized)
 

 Optional Inputs:
   fig_id              - [integer] ID number of the figure window in which GUI is
                         displayed (or will be displayed).
   bin                 - [integer] The ID number of the bin whose power spectra 
                         will be visualized. Note, Kutaslab Bin 0 is ignored and is 
                         assumed to contain cal pulses. Thus bin indexing starts 
                         at 1.  Use headinfo_spec.m to see the set of bins stored in 
                         a specGND or specGRP variable
   t_test              - [integer] The ID number of the set of t-tests whose
                         results will be visualized. If specified, any optional 
                         input arguments inconsistent with this test's parameters
                         (e.g., 'bin') will be ignored.  Note, the results of
                         t-tests performed on voltages averaged across 
                         windows is not possible with this GUI; use sig_topo.m 
                         or sig_raster.m instead. Use headinfo_spec.m to see the 
                         sets of t-test results stored in a specND or specGRP variable      
   show_band           - [vector] Two numbers (in Hz) indicating
                         beginning and end frequencies to visualize (e.g., [0 40]);
   specGND_or_specGRP  - MATLABmk specGND or specGRP structure variable containing the
                         power spectrum data and t-test results to visualize.
   critical_t          - [vector] One or two numbers indicating critical
                         t-score(s). Frequencies/channels with t-scores that 
                         exceed the critical t-score(s) are significantly 
                         different from the mean of the null hypothesis.
   alpha_or_q          - [number] Number between 0 and 1 indicating the family-
                         wise alpha or FDR q level of the critical t-scores.
   test_wind           - [vector] Pairs of numbers (in milliseconds) indicating
                         beginning and end frequencies of the t-test
                         frequency band(s) (e.g., [0 40]).  Multiple
                         frequency bands can be specified by using semicolons 
                         to separate pairs of frequencies (e.g., [3 9; 9
                         13]).
   stat                - ['t', 'rms', or 'stder'] Statistic shown in lower GUI 
                         butterfly plot. 't'=t-scores of power. 'rms'=root mean 
                         squared power. 'stder'=the standard error of power 
                         (derived from the standard deviation across participants.
   exclude_chans       - Cell array of channel labels to exclude from
                         visualization (e.g., {'A2','lle','rhe'}).  If only one
                         channel, a single string (e.g., 'A2') is acceptable.
                         You cannot use this option AND the 't_test' option.
   include_chans       - Cell array of channel labels to include in the
                         visualization (e.g., {'MiPf','MiCe','MiPa','MiOc'}). If 
                         only one channel, a single string (e.g., 'MiCe') is 
                         acceptable.  All other channels will be ignored. You
                         cannot use this option AND the 't_test' option.
   verblevel           - An integer specifiying the amount of information you want
                         this function to provide about what it is doing during runtime.
                         Options are:
                           0 - quiet, only show errors, warnings, and EEGLAB reports
                           1 - stuff anyone should probably know
                           2 - stuff you should know the first time you start working
                               with a data set {default value}
                           3 - stuff that might help you debug (show all
                               reports)

 
 Outputs:
   None


 Author:
 David Groppe
 Kutaslab, 12/2010


 Notes:
 -If you try to use this function to visualize only channels that
 have no scalp coordinates (e.g., the difference between left and right
 hemisphere homologues), the function will automatically use sig_wave.m 
 instead if there are t-tests stored with the data. If there 
 are no t-tests stored with the data, gui_pow.m will simply abort. 

 -If you try to use this function to visualize only two channels that
 have scalp coordinates (e.g., MiPf & MiCe), the function will 
 automatically plot the channel locations instead of the scalp topographies.
 This is because you can't interpolate a topography with only two
 channels.  sig_wave.m is probably a better method than gui_pow.m for 
 visualizing test results at only two channels since when you click on the 
 waveforms the name of the channel corresponding to the waveform appears 
 (i.e., it's easier to determine which waveform corresponds to which channel).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % gui_pow() - Open a GUI for visualzing butterfly plots of EEG power spectra
0002 %             and topographies.  t-scores, standard error and root mean
0003 %             square power can also be visualized. Hold mouse cursor over
0004 %             GUI controls for an explanation of what they do.  Click on
0005 %             data traces to visualize the scalp topography at that
0006 %             frequency. Click on electrodes in scalp topography to see
0007 %             electrode name.  Note, you can open more than one "gui_pow"
0008 %             at a time in different windows, but you cannot animate more
0009 %             than one gui_pow window at a time.
0010 %
0011 % Usage:
0012 %  >> gui_pow(cmnd_str,varargin);
0013 %   or
0014 %  >> gui_pow(specGND_or_specGRP,varargin);
0015 %
0016 % Required Input:
0017 %   cmnd_str   - One of the following strings:
0018 %                   1.  'initialize'(intialize the GUI)
0019 %                   2.  'freq jump'(change the frequency whose topography
0020 %                        is visualized)
0021 %                   3.  'back one'(go back one frequency)
0022 %                   4.  'forward one'(go forward one frequency)
0023 %                   5.  'back'(animate topography going backwards in frequency)
0024 %                   6.  'forward'(animate topography going forwards in frequency)
0025 %                   7.  'change stat'(change the statistic that is being
0026 %                        visualized [t-score, standard error, or RMS])
0027 %                   8.  'new freq limits'(change the x-axis range on the
0028 %                        waveform x frequency axes)
0029 %                   9.  'new statistic limitsA'(change the y-axis range on the
0030 %                        power x frequency axis--i.e., Axis A)
0031 %                   10. 'new statistic limitsB' (change the y-axis range on the
0032 %                        t-score/stderr/rms x frequency axis--i.e., Axis B)
0033 %                   11. 'change bin' (visualize a different bin)
0034 %                   12. 'update dashed lines' (redraws dashed lines
0035 %                        representing t-test frequency window)
0036 %                   13. 'update critical t' (redraws dashed lines
0037 %                        representing t-test critical
0038 %                        t-scores)
0039 %                   14. 'redraw topo' (redraws topographies)
0040 %                   15. 'change test' (change the t-test results being
0041 %                        visualized)
0042 %
0043 %
0044 % Optional Inputs:
0045 %   fig_id              - [integer] ID number of the figure window in which GUI is
0046 %                         displayed (or will be displayed).
0047 %   bin                 - [integer] The ID number of the bin whose power spectra
0048 %                         will be visualized. Note, Kutaslab Bin 0 is ignored and is
0049 %                         assumed to contain cal pulses. Thus bin indexing starts
0050 %                         at 1.  Use headinfo_spec.m to see the set of bins stored in
0051 %                         a specGND or specGRP variable
0052 %   t_test              - [integer] The ID number of the set of t-tests whose
0053 %                         results will be visualized. If specified, any optional
0054 %                         input arguments inconsistent with this test's parameters
0055 %                         (e.g., 'bin') will be ignored.  Note, the results of
0056 %                         t-tests performed on voltages averaged across
0057 %                         windows is not possible with this GUI; use sig_topo.m
0058 %                         or sig_raster.m instead. Use headinfo_spec.m to see the
0059 %                         sets of t-test results stored in a specND or specGRP variable
0060 %   show_band           - [vector] Two numbers (in Hz) indicating
0061 %                         beginning and end frequencies to visualize (e.g., [0 40]);
0062 %   specGND_or_specGRP  - MATLABmk specGND or specGRP structure variable containing the
0063 %                         power spectrum data and t-test results to visualize.
0064 %   critical_t          - [vector] One or two numbers indicating critical
0065 %                         t-score(s). Frequencies/channels with t-scores that
0066 %                         exceed the critical t-score(s) are significantly
0067 %                         different from the mean of the null hypothesis.
0068 %   alpha_or_q          - [number] Number between 0 and 1 indicating the family-
0069 %                         wise alpha or FDR q level of the critical t-scores.
0070 %   test_wind           - [vector] Pairs of numbers (in milliseconds) indicating
0071 %                         beginning and end frequencies of the t-test
0072 %                         frequency band(s) (e.g., [0 40]).  Multiple
0073 %                         frequency bands can be specified by using semicolons
0074 %                         to separate pairs of frequencies (e.g., [3 9; 9
0075 %                         13]).
0076 %   stat                - ['t', 'rms', or 'stder'] Statistic shown in lower GUI
0077 %                         butterfly plot. 't'=t-scores of power. 'rms'=root mean
0078 %                         squared power. 'stder'=the standard error of power
0079 %                         (derived from the standard deviation across participants.
0080 %   exclude_chans       - Cell array of channel labels to exclude from
0081 %                         visualization (e.g., {'A2','lle','rhe'}).  If only one
0082 %                         channel, a single string (e.g., 'A2') is acceptable.
0083 %                         You cannot use this option AND the 't_test' option.
0084 %   include_chans       - Cell array of channel labels to include in the
0085 %                         visualization (e.g., {'MiPf','MiCe','MiPa','MiOc'}). If
0086 %                         only one channel, a single string (e.g., 'MiCe') is
0087 %                         acceptable.  All other channels will be ignored. You
0088 %                         cannot use this option AND the 't_test' option.
0089 %   verblevel           - An integer specifiying the amount of information you want
0090 %                         this function to provide about what it is doing during runtime.
0091 %                         Options are:
0092 %                           0 - quiet, only show errors, warnings, and EEGLAB reports
0093 %                           1 - stuff anyone should probably know
0094 %                           2 - stuff you should know the first time you start working
0095 %                               with a data set {default value}
0096 %                           3 - stuff that might help you debug (show all
0097 %                               reports)
0098 %
0099 %
0100 % Outputs:
0101 %   None
0102 %
0103 %
0104 % Author:
0105 % David Groppe
0106 % Kutaslab, 12/2010
0107 %
0108 %
0109 % Notes:
0110 % -If you try to use this function to visualize only channels that
0111 % have no scalp coordinates (e.g., the difference between left and right
0112 % hemisphere homologues), the function will automatically use sig_wave.m
0113 % instead if there are t-tests stored with the data. If there
0114 % are no t-tests stored with the data, gui_pow.m will simply abort.
0115 %
0116 % -If you try to use this function to visualize only two channels that
0117 % have scalp coordinates (e.g., MiPf & MiCe), the function will
0118 % automatically plot the channel locations instead of the scalp topographies.
0119 % This is because you can't interpolate a topography with only two
0120 % channels.  sig_wave.m is probably a better method than gui_pow.m for
0121 % visualizing test results at only two channels since when you click on the
0122 % waveforms the name of the channel corresponding to the waveform appears
0123 % (i.e., it's easier to determine which waveform corresponds to which channel).
0124 %
0125 
0126 
0127 
0128 %%%%%%%%%%%%%%%%%% NOTES %%%%%%%%%%%%%%%%%%%%%
0129 % -Much of the mechanics of this GUI is based on information that is stored
0130 % in the figure's 'userdata' field.  The fields of the 'userdata are as
0131 % follows:
0132 % >>dat=get(gcf,'userdata')
0133 % dat =
0134 %
0135 %            fig_id: 1<-The Figure ID # of the GUI
0136 %        psbl_tests: [1 2 3 4]<-The sets of t-tests stored in the specGND or
0137 %                    specGRP variable that can be visualized (mean frequency
0138 %                    band tests or tests based on channels not loaded
0139 %                    cannot be visualized)
0140 %           t_tests: [1x4 struct]<-specGND/specGRP.t_test info for the possible tests
0141 %     mltplcmp_crct: 'fdr'<-General method that was used to correct for multiple
0142 %                    comparisons ('fdr' or 'perm')
0143 %             alpha: 0.0532<-q or estimated alpha level of the currently
0144 %                    visualized test
0145 %            n_wind: 1<-# of frequency bands of the currently visualized test
0146 %        critical_t: [-9.4493 9.4493]<-critical t-scores of the currently
0147 %                    visualized test
0148 %         null_mean: 0<-mean of the null hypothesis of the currently
0149 %                    visualized test
0150 %              spec: [31x256x42 double]<-specGND/specGRP.grands_pow_dB
0151 %          t_scores: [31x256x42 double]<-specGND/specGRP.grands_pow_dB_t
0152 %             stder: [31x256x42 double]<-specGND/specGRP.grands_pow_dB_stder
0153 %               dif: [0 0 0 1]<-specGND/specGRP.dif (1 if bin contains the
0154 %                    difference between two other bins)
0155 %               rms: Root mean square of raw power spectra (i.e., not in decibels) [129x4 double]
0156 %         showing_t: [26x256 double]<-t-scores of the data in dat.showing.
0157 %                    These will differ from the values in dat.t_scores if
0158 %                    the mean of the null hypothesis of the test being
0159 %                    visualized is not 0
0160 %          showingB: [26x256 double]<-waveforms currently shown lower
0161 %                    butterfly plot in GUI
0162 %          showingA: [26x256 double]<-waveforms currently shown upper
0163 %                    butterfly plot in GUI
0164 %           bindesc: {1x42 cell}<-bin descriptors for dat.spec
0165 %             freqs: [1x256 double]<-frequencies (in ms) for dat.spec
0166 %         plt_freqs: [0 125]<-start and stop end points for waveforms
0167 %                    currently shown
0168 %          chanlocs: [1x31 struct]<-specGND/specGRP.chanlocs
0169 %      loaded_chans: [3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
0170 %                    23 24 25 26 27 28]<-biggest possible set of channels
0171 %                    that can be visualized
0172 %     showing_chans: [3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
0173 %                    23 24 25 26 27 28]<-set of channels currently
0174 %                    visualized
0175 %           h_freqA: 1.0099<-handle of upper butterfly plot axis
0176 %          start_pt: 1<-first waveform frequency to visualize
0177 %            end_pt: 256<-last waveform frequency to visualize
0178 %            absmxA: 17.1658<-maximum value of absolute value of waveforms
0179 %                    being visualized for upper butterfly plot
0180 %        h_showingA: [31x1 double]<-[26x1 double]<-handle for shown
0181 %                    waveforms in upper butterfly plot
0182 %           h_lineA: 35.0099<-handle for vertical line indicating which
0183 %                    topography is being visualized in upper butterfly plot
0184 %          h_wind1A: 36.0099<-handle for start points of test time
0185 %                    window(s) in upper butterfly plot
0186 %          h_wind2A: 37.0099<-handle for stop points of test time
0187 %                    window(s) in upper butterfly plot
0188 %      h_time_ylabA: 38.0099<-handle for y-axis label on the waveform axis
0189 %                    for upper butterfly plot
0190 %      h_time_title: 39.0099<-handle for title on the waveform axis
0191 %           h_freqB: 41.0099<-handle of lower butterfly plot axis
0192 %            absmxB: 14.5909<-maximum value of absolute value of waveforms
0193 %                    being visualized for lower butterfly plot
0194 %        h_showingB: [31x1 double]<-handle for shown waveforms in lower
0195 %                    butterfly plot
0196 %           h_lineB: 75.0099<-handle for vertical line indicating which
0197 %                    topography is being visualized in lower butterfly plot
0198 %          h_wind1B: 76.0099<-handle for start points of test time
0199 %                    window(s) in lower butterfly plot
0200 %          h_wind2B: 77.0099<-handle for stop points of test time
0201 %                    window(s) in lower butterfly plot
0202 %           h_crit1: 78.0099<-handle for red horizontal dashed line indicating
0203 %                    critical t-score
0204 %           h_crit2: 80.0099<-handle for 2nd red horizontal dashed line indicating
0205 %                    critical t-score (used if two tailed test [i.e., two
0206 %                    critical t-scores])
0207 %           h_alph1: 79.0099<-handle for text box indicating alpha level.
0208 %           h_alph2: 81.0099<-handle for 2nd text box indicating alpha level.
0209 %                    (used if two tailed test [i.e., two critical
0210 %                    t-scores])
0211 %      h_time_ylabB: 83.0099<-handle for y-axis label on the waveform axis
0212 %                    for lower butterfly plot
0213 %           h_topoA: 85.0099<-handle of upper topography axis
0214 %          mx_topoA: the maximum of the color scale on topography A
0215 %          mn_topoA: the minimum of the color scale on topography A
0216 %           h_cbarA: 167.0099<-handle of topography colorbar legend for
0217 %                    upper axis
0218 %       h_topo_freq: 171.0099<-handle of text box indicating the frequency
0219 %                    whose topography is currently being visualized
0220 %           h_topoB: 173.0099<-handle of lower topography axis
0221 %          mx_topoB: the maximum of the color scale on topography B
0222 %          mn_topoB: the minimum of the color scale on topography B
0223 %           h_cbarB: 254.0099<-handle of topography colorbar legend for
0224 %                    lower axis
0225 %           h_back1: 257.0099<-handle of button that moves the vertical
0226 %                    waveform line (i.e., the point whose topography
0227 %                    is currently being visualized) back one frequency
0228 %        h_forward1: 258.0099<-handle of button that moves the vertical
0229 %                    waveform line (i.e., the point whose topography
0230 %                    is currently being visualized) forward one time
0231 %                    point
0232 %            h_back: 259.0099<-handle of button that animates the vertical
0233 %                    waveform line (i.e., the point whose topography
0234 %                    is currently being visualized) back in time
0235 %         h_forward: 260.0099<-handle of button that animates the vertical
0236 %                    waveform line (i.e., the point whose topography
0237 %                    is currently being visualized) forward in time
0238 %            h_stop: 261.0099<-handle of button that stops animation of the
0239 %                    vertical waveform line (i.e., the point whose
0240 %                    topography is currently being visualized)
0241 %             h_bin: 264.0099<-handle of the scroll menu indicating which
0242 %                    bin is being visualized
0243 %           h_ptest: 266.0099<-handle of the scroll menu indicating which
0244 %                    set of t-tests are being visualized
0245 %        h_testwind: 268.0099<-handle of the text box indicating the
0246 %                    boundaries of the t-test frequency bands
0247 %         h_critval: 270.0099<-handle of the text box indicating the
0248 %                    critical t-score values of the set of t-tests
0249 %            h_stat: 272.0099<-handle of the scroll menu indicating which
0250 %                    statistic to plot (t-score, standard
0251 %                    error, RMS)
0252 %       h_freqrange: 274.0099<-handle of the text box indicating the
0253 %                    minimum and maximum time values on the waveform axis
0254 %      h_statrangeA: 276.0099<-handle of the text box indicating the
0255 %                    minimum and maximum statistics values on the
0256 %                    upper butterfly plot (i.e., Axis A: power spectra)
0257 %      h_statrangeB: 278.0099<-handle of the text box indicating the
0258 %                    minimum and maximum statistics values on the
0259 %                    lower butterfly plot (i.e., Axis A: t-scores,
0260 %                    standard error, RMS)
0261 %          help_msg: [1x447 char]<-message displayed when help button is
0262 %                    pressed
0263 %         interrupt: 1<- field for topography animation
0264 
0265 
0266 %%%%%%%%% POSSIBLE FUTURE DEVELOPMENT %%%%%%%%%
0267 %
0268 %-Make it possible to animate more than one GUI at a time?
0269 %
0270 %-Make it possible to change topo color limits?  I don't know how do-able
0271 %this is since values that exceed topo color limits are impossible to
0272 %distinguish from values that are at the topo color limits.  Currently topo
0273 %is automatically scaled to +/- the absolute maxima of the waveforms
0274 %currently shown (parts of the waveform before/after the "showing time
0275 %window" are ignored).
0276 %
0277 %-Make it possible to right-click on axis to get them to pop-up in a new
0278 %figure?
0279 %
0280 %-Make color scheme same as EEGLAB GUIs (see variabl frm_col)?
0281 %
0282 %-Make time x erp axis title an optional input argument?
0283 %
0284 %-Make topo scale an option
0285 %
0286 %-Set topo color scale to green or empty when only one channel?, or delete
0287 % it?
0288 %
0289 %-Add Cohen's d as a possible statistic?
0290 %
0291 %-Possibly fix use of axes command (see yellow warnings) to speed up
0292 % animations?
0293 %
0294 %-Make frm_col=[1 1 1]*.702 the same light blue color as EEGLAB later
0295 % (currently it's gray)?
0296 
0297 
0298 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0299 % 12/17/2010-Code checks to make sure requested bin exists
0300 
0301 function gui_pow(cmnd_str,varargin)
0302 
0303 p=inputParser;
0304 p.addRequired('cmnd_str',@(x) ischar(x) || isstruct(x));
0305 p.addParamValue('fig_id',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1)));
0306 p.addParamValue('bin',1,@(x) isnumeric(x) && (length(x)==1));
0307 p.addParamValue('show_band',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==2)));
0308 p.addParamValue('specGND_or_specGRP',[],@isstruct);
0309 p.addParamValue('critical_t',[],@(x) isempty(x) || (isnumeric(x) && (length(x)<=2)));
0310 p.addParamValue('test_wind',[],@(x) isempty(x) || (isnumeric(x) && (size(x,2)==2)));
0311 p.addParamValue('stat','t',@(x) ischar(x) || strcmpi(x,'t') || strcmpi(x,'stder'));
0312 p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0313 p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x) || isempty(x));
0314 p.addParamValue('alpha_or_q',[],@(x) isempty(x) || isnumeric(x));
0315 p.addParamValue('t_test',[],@(x) isempty(x) || (isnumeric(x) && (length(x)==1) && (x>0)));
0316 p.addParamValue('verblevel',2,@(x) isnumeric(x) && (length(x)==1));
0317 p.parse(cmnd_str,varargin{:});
0318 
0319 
0320 if isstruct(cmnd_str)
0321     % Assume cmnd_str is really a specGND or specGRP variable and that the desired
0322     % command string is 'initialize'.  Call gui_pow with same
0323     % optional arguments
0324     gui_pow('initialize','specGND_or_specGRP',cmnd_str,'fig_id',p.Results.fig_id, ...
0325         'bin',p.Results.bin, ...
0326         'critical_t',p.Results.critical_t, ...
0327         'test_wind',p.Results.test_wind, ...
0328         'show_band',p.Results.show_band, ...
0329         'stat',p.Results.stat, ...
0330         'exclude_chans',p.Results.exclude_chans, ...
0331         'include_chans',p.Results.include_chans, ...
0332         'alpha_or_q',p.Results.alpha_or_q, ...
0333         't_test',p.Results.t_test, ...
0334         'verblevel',p.Results.verblevel);
0335     return;
0336 end
0337 
0338 % Ensure passed command is legal
0339 psbl_cmnds{1}='initialize';
0340 psbl_cmnds{2}='freq jump';
0341 psbl_cmnds{3}='back one';
0342 psbl_cmnds{4}='forward one';
0343 psbl_cmnds{5}='back';
0344 psbl_cmnds{6}='forward';
0345 psbl_cmnds{7}='change stat';
0346 psbl_cmnds{8}='new freq limits';
0347 psbl_cmnds{9}='new statistic limitsA';
0348 psbl_cmnds{10}='change bin';
0349 psbl_cmnds{11}='new statistic limitsB';
0350 psbl_cmnds{12}='update dashed lines';
0351 psbl_cmnds{13}='update critical t';
0352 psbl_cmnds{14}='redraw topo';
0353 psbl_cmnds{15}='change test';
0354 if ~ismember(cmnd_str,psbl_cmnds),
0355     error('''%s'' is not a valid value of cmnd_str for gui_pow.m',cmnd_str); 
0356 end
0357 
0358 
0359 if ~strcmp(cmnd_str,'initialize')
0360     if isempty(p.Results.fig_id),
0361         fig_id=gcbf;
0362     else
0363         fig_id=p.Results.fig_id;
0364     end
0365     if ~strcmp(get(fig_id,'tag'),'gui_pow')
0366         % If the current figure does not have the right
0367         % tag, find the one that does.
0368         h_figs = get(0,'children');
0369         fig_id = findobj(h_figs,'flat',...
0370             'tag','gui_pow');
0371         if isempty(fig_id),
0372             % If gui_pow does not exist
0373             % initialize it. Then run the command string
0374             % that was originally requested.
0375             gui_pow('initialize');
0376             gui_pow(cmnd_str);
0377             return;
0378         end
0379     end
0380     
0381     % At this point we know that h_fig is the handle
0382     % to a figure containing the GUI of interest to
0383     % this function (it's possible that more than one of these
0384     % GUI figures is open).  Therefore we can use this figure
0385     % handle to cut down on the number of objects
0386     % that need to be searched for tag names as follows:
0387     dat=get(gcbf,'userdata');
0388 end
0389 
0390 % Manage VERBLEVEL
0391 if isempty(p.Results.verblevel),
0392     VERBLEVEL=2; %not global, just local
0393 else
0394     VERBLEVEL=p.Results.verblevel;
0395 end
0396 
0397 % INITIALIZE THE GUI SECTION.
0398 if strcmp(cmnd_str,'initialize')
0399     if isempty(p.Results.specGND_or_specGRP.grands_pow_dB)
0400         error('There are no bins in this specGND or specGRP variable.  You need to add bins before you can visualize them with the spectral power GUI.');
0401     end
0402     
0403     % Creates a new GUI (even if one already exists)
0404     if isempty(p.Results.fig_id),
0405         dat.fig_id=figure;
0406     else
0407         dat.fig_id=p.Results.fig_id;
0408         figure(dat.fig_id);
0409         clf
0410     end
0411     set(dat.fig_id,'name',['POW GUI ' p.Results.specGND_or_specGRP.exp_desc],'tag','gui_pow', ...
0412         'MenuBar','none','position',[139 42 690 700]);
0413     
0414     %% Manage t-test results
0415     n_t_tests=length(p.Results.specGND_or_specGRP.t_tests);
0416     dat.psbl_tests=[];
0417     temp_bins=zeros(1,n_t_tests);
0418     for d=1:n_t_tests,
0419         if ~strcmpi(p.Results.specGND_or_specGRP.t_tests(d).mean_band,'yes'),
0420             dat.psbl_tests=[dat.psbl_tests d];
0421             temp_bins(d)=p.Results.specGND_or_specGRP.t_tests(d).bin;
0422         end
0423     end
0424     temp_bins=temp_bins(dat.psbl_tests);
0425     n_psbl_tests=length(dat.psbl_tests);
0426     dat.t_tests=p.Results.specGND_or_specGRP.t_tests(dat.psbl_tests);
0427     crnt_ttest=n_psbl_tests+1; %set of t-tests being visualized, default is None/Manual
0428     
0429     use_ttest=0;
0430     if isempty(p.Results.t_test),
0431         if isempty(p.Results.include_chans) && isempty(p.Results.exclude_chans) ...
0432                 && isempty(p.Results.critical_t) && isempty(p.Results.alpha_or_q) ...
0433                 && isempty(p.Results.test_wind),
0434             %search for set of t-tests that have been performed on bin being
0435             %visualized (if potentially incompatible optional input
0436             %arguments have NOT been specified
0437             test_ids=find(p.Results.bin==temp_bins);
0438             if ~isempty(test_ids),
0439                 use_ttest=1;
0440                 crnt_ttest=test_ids(1); %in case there's more than one test
0441                 if VERBLEVEL>=2
0442                     fprintf('Plotting results of t-tests set %d.  Any input arguments (e.g., ''critical_t'') inconsistent with this test will be ignored.\n', ...
0443                         dat.psbl_tests(crnt_ttest));
0444                 end
0445             end
0446         end
0447     else
0448         if p.Results.t_test>n_t_tests,
0449             error('Argument ''t_test'' value of %d exceeds the number of test results stored in this specGND/specGRP variable (i.e., %d).', ...
0450                 p.Results.t_test,n_t_tests);
0451         elseif ~ismember(p.Results.t_test,dat.psbl_tests),
0452             error('t-test set %d in this specGND/specGRP variable was performed on mean amplitudes within one or more frequency bands.  You cannot visualize such tests with gui_pow.m.', ...
0453                 p.Results.t_test);
0454         else
0455             use_ttest=1;
0456             crnt_ttest=find(dat.psbl_tests==p.Results.t_test);
0457             if VERBLEVEL>=2
0458                 fprintf('Plotting results of t-test set %d.  Any input arguments (e.g., ''bin'') inconsistent with this test will be ignored.\n', ...
0459                     p.Results.t_test);
0460             end
0461         end
0462     end
0463     if use_ttest,
0464         % set all other optional arguments to be
0465         % consistent with t-test
0466         bin=dat.t_tests(crnt_ttest).bin;
0467         if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
0468             dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
0469             dat.mltplcmp_crct='fdr';
0470         else
0471             dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
0472             dat.mltplcmp_crct='perm';
0473         end
0474         test_wind=dat.t_tests(crnt_ttest).freq_band;
0475         dat.n_wind=size(test_wind,1);
0476         include_chans=dat.t_tests(crnt_ttest).include_chans;
0477         dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
0478         dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
0479     else
0480         % no t-test, use optional inputs or defaults
0481         bin=p.Results.bin;
0482         test_wind=p.Results.test_wind;
0483         include_chans=p.Results.include_chans;
0484         dat.alpha=p.Results.alpha_or_q;
0485         dat.critical_t=p.Results.critical_t;
0486         dat.null_mean=0;
0487     end
0488  
0489     
0490     %% Make sure user hasn't asked for a bin that doesn't exist
0491     if bin>size(p.Results.specGND_or_specGRP.grands_pow_dB,3)
0492         close(gcf);
0493         error('You asked to visualize Bin %d, but your specGND/specGRP variable only contains %d bins.', ...
0494             bin,size(p.Results.specGND_or_specGRP.grands_pow_dB,3));
0495     end
0496         
0497     %% Figure out which channels to ignore if any
0498     n_chan=length(p.Results.specGND_or_specGRP.chanlocs);
0499     %Make sure exclude & include options were not both used.
0500     if ~isempty(include_chans) && ~isempty(p.Results.exclude_chans)
0501         if use_ttest,
0502             error('You cannot specify a set of t-tests to visualize and use the ''exclude_chans'' option.');
0503         else
0504             error('You cannot use BOTH ''include_chans'' and ''exclude_chans'' options.');
0505         end
0506     end
0507     if ischar(p.Results.exclude_chans),
0508         exclude_chans{1}=p.Results.exclude_chans;
0509     elseif isempty(p.Results.exclude_chans)
0510         exclude_chans=[];
0511     else
0512         exclude_chans=p.Results.exclude_chans;
0513     end
0514     if ischar(include_chans),
0515         temp_var=include_chans;
0516         clear include_chans;
0517         include_chans{1}=temp_var;
0518         clear temp_var;
0519     end
0520     if ~isempty(exclude_chans),
0521         ignore_chans=zeros(1,length(exclude_chans)); %preallocate mem
0522         ct=0;
0523         for x=1:length( exclude_chans),
0524             found=0;
0525             for c=1:n_chan,
0526                 if strcmpi(exclude_chans{x},p.Results.specGND_or_specGRP.chanlocs(c).labels),
0527                     found=1;
0528                     ct=ct+1;
0529                     ignore_chans(ct)=c;
0530                 end
0531             end
0532             if ~found,
0533                 watchit(sprintf('I attempted to exclude %s.  However no such electrode was found in specGND/specGRP variable.', ...
0534                     exclude_chans{x}));
0535             end
0536         end
0537         ignore_chans=ignore_chans(1:ct);
0538         loaded_chans=setdiff(1:n_chan,ignore_chans);
0539     elseif ~isempty(include_chans),
0540         loaded_chans=zeros(1,length(include_chans)); %preallocate mem
0541         ct=0;
0542         for x=1:length(include_chans),
0543             found=0;
0544             for c=1:n_chan,
0545                 if strcmpi(include_chans{x},p.Results.specGND_or_specGRP.chanlocs(c).labels),
0546                     found=1;
0547                     ct=ct+1;
0548                     loaded_chans(ct)=c;
0549                 end
0550             end
0551             if ~found,
0552                 watchit(sprintf('I attempted to include %s.  However no such electrode was found in specGND/specGRP variable.', ...
0553                     include_chans{x}));
0554             end
0555         end
0556         loaded_chans=loaded_chans(1:ct);
0557     else
0558         loaded_chans=1:n_chan;
0559     end
0560     if isempty(loaded_chans),
0561         error('No channels selected for visualization!');
0562     end
0563     %Check to see if any channels are missing coordinates
0564     yes_coord=zeros(1,n_chan);
0565     for c=loaded_chans,
0566         if ~isempty(p.Results.specGND_or_specGRP.chanlocs(c).theta) && ~isnan(p.Results.specGND_or_specGRP.chanlocs(c).theta)
0567             yes_coord(c)=1;
0568         end
0569     end
0570     if (sum(yes_coord)==0)
0571         if use_ttest
0572             %t-test results should be shown
0573             watchit(sprintf('None of the channels you wish to visualize have scalp coordinates.\nIt is pointless to use the gui_pow.m.  Using sig_wave.m instead.'));
0574             close(gcf);
0575             sig_wave(p.Results.specGND_or_specGRP,crnt_ttest, ...
0576                 'verblevel',p.Results.verblevel);
0577         else
0578             watchit('None of the channels you wish to visualize have scalp coordinates.  It is pointless to use the gui_pow.m.');
0579             close(gcf);
0580         end
0581         return
0582     elseif sum(yes_coord)<length(loaded_chans),
0583         watchit(sprintf('%d channels do not have scalp coordinates.  The spectra for such channels will be visualized but they the will not be represented in the scalp topography.', ...
0584             length(loaded_chans)-sum(yes_coord)));
0585     end
0586     
0587     %remove any sets of t-tests peformed on channels that will not be
0588     %included in the GUI
0589     use_tests=[];
0590     for d=1:n_psbl_tests,
0591        if ~isempty(intersect(loaded_chans,dat.t_tests(d).used_chan_ids)),
0592           use_tests=[use_tests d]; 
0593        end
0594     end
0595     dat.psbl_tests=dat.psbl_tests(use_tests);
0596     dat.t_tests=dat.t_tests(use_tests);
0597     crnt_ttest=find(crnt_ttest==[use_tests n_psbl_tests+1]); % "n_psbl_tests+1" adds the manual/no test option
0598     n_psbl_tests=length(use_tests);
0599     
0600     %% attach data to figure
0601     dat.spec=p.Results.specGND_or_specGRP.grands_pow_dB;
0602     dat.t_scores=p.Results.specGND_or_specGRP.grands_pow_dB_t;
0603     dat.stder=p.Results.specGND_or_specGRP.grands_pow_dB_stder;
0604     dat.dif=p.Results.specGND_or_specGRP.dif;
0605     for dd=1:length(dat.dif),
0606         if dat.dif(dd),
0607             %bin is the difference between two other bins, no need to
0608             %convert difference
0609             dat.rms(:,dd)=squeeze(sqrt(mean(dat.spec(:,:,dd).^2,1)))';
0610         else
0611             %bin is NOT the difference between two other bins, need to
0612             %convert from decibels back to power spectra difference
0613             non_db=(10.^(dat.spec(:,:,dd)/10));
0614             dat.rms(:,dd)=squeeze(sqrt(mean(non_db,1)))';
0615         end
0616     end
0617     %t-scores of data that will be shown
0618     if (crnt_ttest<=n_psbl_tests) && (dat.t_tests(crnt_ttest).null_mean),
0619         %The mean of the null hypothesis is non-zero
0620         dat.showing_t=squeeze( (p.Results.specGND_or_specGRP.grands_pow_dB(loaded_chans,:,bin)- ...
0621             dat.t_tests(crnt_ttest).null_mean)./p.Results.specGND_or_specGRP.grands_pow_dB_stder(loaded_chans,:,bin) ); 
0622     else
0623         dat.showing_t=squeeze(p.Results.specGND_or_specGRP.grands_pow_dB_t(loaded_chans,:,bin)); 
0624     end
0625     %data that will be shown
0626     if isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)) || strcmpi(p.Results.stat,'rms'),
0627         %default to root mean squared if there's only one subject in the
0628         %bin (and standard deviation isn't defined). For within-subject
0629         %t-scores, stdev will bin Inf/-Inf when there's only one subject.
0630         %For between-subject t-scores, stdev will bin NaN when there are
0631         %insufficient subjects in one or both groups.
0632         dat.showingB=dat.rms(:,bin)'; 
0633     elseif strcmpi(p.Results.stat,'t'),
0634         dat.showingB=dat.showing_t;
0635     else
0636         %standard error
0637         dat.showingB=squeeze(p.Results.specGND_or_specGRP.grands_pow_dB_stder(loaded_chans,:,bin)); 
0638     end
0639     dat.showingA=squeeze(p.Results.specGND_or_specGRP.grands_pow_dB(loaded_chans,:,bin)); %always show spectral power in top axis
0640     
0641     n_bin=size(p.Results.specGND_or_specGRP.grands_pow_dB,3);
0642     dat.bindesc=cell(1,n_bin);
0643     for b=1:n_bin,
0644         if isfield(p.Results.specGND_or_specGRP,'bindesc'),
0645             dat.bindesc{b}=p.Results.specGND_or_specGRP.bindesc{b};
0646         else
0647             dat.bindesc{b}=p.Results.specGND_or_specGRP.bin_info(b).bindesc;
0648         end
0649     end
0650     dat.freqs=p.Results.specGND_or_specGRP.freqs;
0651     if isempty(p.Results.show_band),
0652         dat.plt_freqs=[p.Results.specGND_or_specGRP.freqs(1) p.Results.specGND_or_specGRP.freqs(end)];
0653     else
0654         dat.plt_freqs=p.Results.show_band;
0655     end
0656     dat.chanlocs=p.Results.specGND_or_specGRP.chanlocs;
0657     dat.loaded_chans=loaded_chans;
0658     dat.showing_chans=loaded_chans;
0659     critical_t=dat.critical_t;
0660     if length(critical_t)>2,
0661        critical_t=critical_t(1:2); 
0662     end
0663     dat.critical_t=critical_t;
0664     
0665     %
0666     %%%%%%%%%%%%%%%%%%%%%% AXIS A: Frequency x Power Axes %%%%%%%%%%%%%%%%%%%%%%%%
0667     %
0668     
0669     frm_col=[1 1 1]*.702;
0670     uipanel(dat.fig_id,...
0671         'Units','normalized', ...
0672         'Position',[ 0 0.59 .72 0.42 ],...
0673         'shadowcolor','k', ...
0674         'highlightcolor',frm_col, ...
0675         'foregroundcolor',frm_col, ...
0676         'backgroundcolor',frm_col);
0677     
0678     dat.h_freqA=axes('position',[0.1 .62 .6 .33]);
0679     dat.start_pt=find_tpt(dat.plt_freqs(1),dat.freqs);
0680     dat.end_pt=find_tpt(dat.plt_freqs(2),dat.freqs);
0681     plotted_pts=dat.start_pt:dat.end_pt;
0682     plotted_freqs=dat.freqs(dat.start_pt:dat.end_pt);
0683     dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
0684     [dummy, mx_tpt]=max(dat.rms(dat.start_pt:dat.end_pt,bin));
0685     stat_mx=max(max(dat.showingA(:,dat.start_pt:dat.end_pt)));
0686     stat_mn=min(min(dat.showingA(:,dat.start_pt:dat.end_pt)));
0687     stat_rng=stat_mx-stat_mn;
0688     stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
0689     stat_plt_rng=round(stat_plt_rng*100)/100;
0690     if dat.dif(bin)
0691         dat.h_db_zeroA=plot([p.Results.specGND_or_specGRP.freqs(1) p.Results.specGND_or_specGRP.freqs(end)],[0 0],'k'); % Power=0 line, only draw for difference bins
0692     else
0693         dat.h_db_zeroA=[];
0694     end
0695     hold on;
0696     set(dat.h_freqA,'ygrid','on');
0697     if size(dat.showingA,1)==1,
0698         %only one channel being plot
0699         dat.h_showingA=plot(dat.freqs,dat.showingA);
0700     else
0701         dat.h_showingA=plot(dat.freqs,dat.showingA');
0702     end
0703     axis tight;
0704     axis([plotted_freqs(1) plotted_freqs(end) stat_plt_rng]);
0705     vA=axis;
0706     dat.h_lineA=plot([1 1]*plotted_freqs(mx_tpt),vA(3:4),'k'); % line indicating current frequency
0707     set(dat.h_lineA,'linewidth',2);
0708     
0709     % Dashed vertical lines marking test window
0710     dat.n_wind=size(test_wind,1);
0711     if dat.n_wind        
0712         for nw=1:dat.n_wind,
0713             dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),vA(3:4),'k--');
0714             set(dat.h_wind1A(nw),'linewidth',2);
0715             dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),vA(3:4),'k--');
0716             set(dat.h_wind2A(nw),'linewidth',2);
0717         end
0718     else
0719         dat.h_wind1A=[];
0720         dat.h_wind2A=[];
0721     end
0722     
0723     %y-axis
0724     h=ylabel('10*log10(\muV^2/Hz)');
0725     dat.h_freq_ylabA=h;
0726     set(h,'fontsize',10,'fontunits','normalized');
0727     
0728     %Title
0729     new_title=['Bin ' int2str(bin) ': ' dat.bindesc{bin}];
0730     title_max_char=43; %prevents title from spilling over into topography axis
0731     if length(new_title)>title_max_char,
0732         new_title=new_title(1:title_max_char);
0733     end 
0734     dat.h_freq_title=title(new_title);
0735     set(dat.h_freq_title,'fontsize',10,'fontunits','normalized');
0736     bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0737         'dat=get(gcbf, ''userdata'');' ...
0738         'new_freq=find_tpt(tmppos(1,1),dat.freqs);' ...
0739         'set(dat.h_lineA,''XData'',[1 1]*dat.freqs(new_freq));' ...
0740         'set(dat.h_lineB,''XData'',[1 1]*dat.freqs(new_freq));' ...
0741         'set(dat.h_topo_freq,''string'',num2str(dat.freqs(new_freq)));' ...
0742         'set(dat.fig_id,''userdata'',dat);' ...
0743         'gui_pow(''redraw topo'');' ...
0744         'drawnow;' ...
0745         'clear latpoint dattmp tmppos;' ...
0746         ];
0747     set(dat.h_freqA,'ButtonDownFcn',bdf_code);
0748     set(dat.h_showingA,'ButtonDownFcn',bdf_code);
0749 
0750     
0751     %
0752     %%%%%%%%%%%%%%%%%%%%%% AXIS B: Frequency x t-score/stderr/RMS Axes %%%%%%%%%%%%%%%%%%%%%%%%
0753     %
0754     
0755     frm_col=[1 1 1]*.702; %background color (gray) differs from EEGLAB blue background color
0756     uipanel(dat.fig_id,...
0757         'Units','normalized', ...
0758         'Position',[ 0 0.175 .72 0.42 ],...
0759         'shadowcolor','k', ...
0760         'highlightcolor',frm_col, ...
0761         'foregroundcolor',frm_col, ...
0762         'backgroundcolor',frm_col);
0763    
0764     dat.h_freqB=axes('position',[0.1 .25 .6 .33]); 
0765     dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
0766     stat_mx=max(max(dat.showingB(:,dat.start_pt:dat.end_pt)));
0767     stat_mn=min(min(dat.showingB(:,dat.start_pt:dat.end_pt)));
0768     stat_rng=stat_mx-stat_mn;
0769     stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
0770     stat_plt_rng=round(stat_plt_rng*100)/100;
0771     if dat.dif(bin) && strcmpi(p.Results.stat,'t') 
0772         dat.h_db_zeroB=plot([p.Results.specGND_or_specGRP.freqs(1) p.Results.specGND_or_specGRP.freqs(end)],[0 0],'k'); % Power=0 line, only draw for difference bins
0773     else
0774         dat.h_db_zeroB=[];
0775     end
0776     hold on;
0777     set(dat.h_freqB,'ygrid','on');
0778     if size(dat.showingB,1)==1,
0779         %only one channel being plot
0780         dat.h_showingB=plot(dat.freqs,dat.showingB);
0781     else
0782         dat.h_showingB=plot(dat.freqs,dat.showingB');
0783     end
0784     axis tight;
0785     axis([plotted_freqs(1) plotted_freqs(end) stat_plt_rng]);
0786     vB=axis;
0787     dat.h_lineB=plot([1 1]*plotted_freqs(mx_tpt),vB(3:4),'k');
0788     set(dat.h_lineB,'linewidth',2);
0789     
0790     % Dashed vertical lines marking test window
0791     if dat.n_wind        
0792         for nw=1:dat.n_wind,
0793             dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),vB(3:4),'k--');
0794             set(dat.h_wind1B(nw),'linewidth',2);
0795             dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),vB(3:4),'k--');
0796             set(dat.h_wind2B(nw),'linewidth',2);
0797         end
0798     else
0799         dat.h_wind1B=[];
0800         dat.h_wind2B=[];
0801     end
0802     
0803     % Dashed lines marking critical t-score(s)
0804     dat.h_crit1=[];
0805     dat.h_crit2=[];
0806     dat.h_alph1=[];
0807     dat.h_alph2=[];
0808     if ~isempty(critical_t) && ~isempty(test_wind),
0809         if strcmpi(p.Results.stat,'t'),
0810             if isempty(dat.alpha),
0811                 watchit('You did not specify an alpha level via optional input argument ''alpha''.  Alpha level will not be displayed.');
0812             else
0813                 for nw=1:dat.n_wind,
0814                     dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*critical_t(1),'r--');
0815                     set(dat.h_crit1(nw),'linewidth',3);
0816                     if nw==1,
0817                         tm_rng=p.Results.specGND_or_specGRP.freqs(end)-p.Results.specGND_or_specGRP.freqs(1);
0818                         if strcmpi(dat.mltplcmp_crct,'fdr')
0819                             dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
0820                                 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
0821                         else
0822                             dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,critical_t(1), ...
0823                                 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
0824                         end
0825                         set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
0826                             'horizontalalignment','right','backgroundcolor',[1 1 1], ...
0827                             'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
0828                     end
0829                 end
0830             end
0831             if length(critical_t)>1,
0832                 for nw=1:dat.n_wind,
0833                     dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*critical_t(2),'r--');
0834                     set(dat.h_crit2(nw),'linewidth',3);
0835                     if nw==1,
0836                         if strcmpi(dat.mltplcmp_crct,'fdr')
0837                             dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
0838                                 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
0839                         else
0840                             dat.h_alph2=text(test_wind(nw,1)-tm_rng*.02,critical_t(2), ...
0841                                 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
0842                         end
0843                         set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
0844                             'horizontalalignment','right','backgroundcolor',[1 1 1], ...
0845                             'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
0846                     end
0847                 end
0848             end
0849         end
0850     end
0851     %x-axis label
0852     h=xlabel('Frequency (Hz)');
0853     set(h,'fontsize',10,'fontunits','normalized');
0854     
0855     %y-axis label
0856     if strcmpi(p.Results.stat,'rms') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin)),
0857         h=ylabel('\muV/sqrt(Hz) (RMS)');
0858     elseif strcmpi(p.Results.stat,'t'),
0859         h=ylabel('t-score');
0860     else
0861         h=ylabel('10*log10(\muV^2/Hz) (StdEr)');
0862     end
0863     dat.h_freq_ylabB=h;
0864     set(h,'fontsize',10,'fontunits','normalized');
0865     
0866     bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
0867         'dat=get(gcbf, ''userdata'');' ...
0868         'new_freq=find_tpt(tmppos(1,1),dat.freqs);' ...
0869         'set(dat.h_lineA,''XData'',[1 1]*dat.freqs(new_freq));' ...
0870         'set(dat.h_lineB,''XData'',[1 1]*dat.freqs(new_freq));' ...
0871         'set(dat.h_topo_freq,''string'',num2str(dat.freqs(new_freq)));' ...
0872         'set(dat.fig_id,''userdata'',dat);' ...
0873         'gui_pow(''redraw topo'');' ...
0874         'drawnow;' ...
0875         'clear latpoint dattmp tmppos;' ...
0876         ];
0877     set(dat.h_freqB,'ButtonDownFcn',bdf_code);
0878     set(dat.h_showingB,'ButtonDownFcn',bdf_code);
0879 
0880     %
0881     %%%%%%%%%%%%%%%%%%%%%% AXIS C: Power Spectra Topography %%%%%%%%%%%%%%%%%%%%%%%%
0882     %
0883 
0884     % PANEL
0885     uipanel(dat.fig_id,...
0886         'Units','normalized', ...
0887         'Position',[ 0.719 0.59 0.281 0.42 ],...
0888         'shadowcolor','k', ...
0889         'highlightcolor',frm_col, ...
0890         'foregroundcolor',frm_col, ...
0891         'backgroundcolor',frm_col);   
0892     
0893     % TOPOGRAPHY
0894     dat.h_topoA=axes('position',[0.705 .68 .31 .24],'box','off');
0895 
0896     sig_chans=[];
0897     cbar_title_fontsize=14;
0898     if ~isempty(test_wind) && ~isempty(critical_t),
0899         %if current frequency is in a test window look for channels with
0900         %sig effects
0901         for nw=1:dat.n_wind,
0902             if (dat.freqs(plotted_pts(mx_tpt))>=test_wind(nw,1)) && (dat.freqs(plotted_pts(mx_tpt))<=test_wind(nw,2)),
0903                 if length(critical_t)==2,
0904                     sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>max(critical_t));
0905                     sig_chans=[sig_chans; find(dat.showing_t(:,plotted_pts(mx_tpt))<min(critical_t))];
0906                 else
0907                     if critical_t>0,
0908                         sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>critical_t);
0909                     else
0910                         sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))<critical_t);
0911                     end
0912                 end
0913                 break;
0914             end
0915         end
0916     end
0917     if size(dat.showingA,1)<=2,
0918         %two or less channels, we can only plot electrode locations
0919         topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0920             'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
0921         cbar_title='Not Applicable';
0922         cbar_title_fontsize=10; %for some reason a fontsize of 14 cuts off last letter for topoB axis
0923         topo_xtick_labA={' ',' ',' '};
0924     else
0925         %More than one channel showing; show color topography
0926         if dat.dif(bin),
0927             %difference between bins, used a fixed color scale
0928             dat.mx_topoA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
0929             dat.mn_topoA=-dat.mx_topoA;
0930         else
0931             %non-difference bin, make color scale unique to time point
0932             %dat.mx_topoA=max(abs(dat.showingA(:,plotted_pts(mx_tpt))));
0933             dat.mx_topoA=max(dat.showingA(:,plotted_pts(mx_tpt)));
0934             dat.mn_topoA=min(dat.showingA(:,plotted_pts(mx_tpt)));
0935         end
0936         topoplotMK(dat.showingA(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
0937             'maplimits',[dat.mn_topoA dat.mx_topoA],'emarker2',{sig_chans,'o',[1 1 1],4});
0938         set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
0939         cbar_title='10*log10(\muV^2/Hz)';
0940         topo_xtick_labA=[dat.mn_topoA 0 dat.mx_topoA];
0941         topo_xtick_labA=round(topo_xtick_labA*100)/100;
0942     end
0943 
0944     
0945     % COLOR BAR
0946     dat.h_cbarA=axes('position',[0.76 .945 .2 .015]);
0947     cbar(dat.h_cbarA);
0948     set(gca,'xticklabel',topo_xtick_labA);
0949     h_cbar_title=title(cbar_title);
0950     set(h_cbar_title,'fontsize',cbar_title_fontsize);
0951     
0952     
0953     %%% FREQUENCY TEXT BOX
0954     %STATIC TEXT LABEL
0955     uicontrol(dat.fig_id,...
0956         'Units','normalized', ...
0957         'Position',[ 0.905 0.62 0.07 0.04 ],...
0958         'String','Hz',...
0959         'fontsize',14, ...
0960         'fontunits','normalized', ...
0961         'Style','text');
0962     dat.h_topo_freq=uicontrol(dat.fig_id,...
0963         'CallBack','gui_pow(''freq jump'');',...
0964         'Units','normalized', ...
0965         'Position',[ 0.805 0.62 0.1 0.05 ], ...
0966         'String',num2str(plotted_freqs(mx_tpt)), ...
0967         'Style','edit', ...
0968         'Enable','on', ...
0969         'ToolTipString','Frequency to visualize topographicaly.', ...
0970         'fontsize',14, ...
0971         'fontunits','normalized', ...
0972         'horizontalalignment','center', ...
0973         'BackGroundColor','w', ...
0974         'Tag','topo_freq');
0975     
0976     
0977     %
0978     %%%%%%%%%%%%%%%%%%%%%% AXIS D: t-Score/Standard Error/RMS Topography %%%%%%%%%%%%%%%%%%%%%%%%
0979     %
0980     
0981     
0982     % PANEL
0983     uipanel(dat.fig_id,...
0984         'Units','normalized', ...
0985         'Position',[ 0.719 0.175 0.281 0.42 ],...
0986         'shadowcolor','k', ...
0987         'highlightcolor',frm_col, ...
0988         'foregroundcolor',frm_col, ...
0989         'backgroundcolor',frm_col);
0990     
0991     % TOPOGRAPHY
0992     dat.h_topoB=axes('position',[0.705 .27 .31 .24],'box','off');
0993     
0994     cbar_title_fontsize=14;
0995     if strcmpi(p.Results.stat,'rms') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
0996         %Just show channel locations
0997         topoplotMK([],dat.chanlocs(dat.showing_chans), ...
0998             'style','blank','plain_blank',1);
0999         cbar_title='Not Applicable';
1000         cbar_title_fontsize=10;
1001         topo_xtick_labB={' ',' ',' '};
1002     else
1003         sig_chans=[];
1004         if ~isempty(test_wind) && ~isempty(critical_t),
1005             %if current frequency is in a test window look for channels with
1006             %sig effects
1007             for nw=1:dat.n_wind,
1008                 if (dat.freqs(plotted_pts(mx_tpt))>=test_wind(nw,1)) && (dat.freqs(plotted_pts(mx_tpt))<=test_wind(nw,2)),
1009                     if length(critical_t)==2,
1010                         sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>max(critical_t));
1011                         sig_chans=[sig_chans; find(dat.showing_t(:,plotted_pts(mx_tpt))<min(critical_t))];
1012                     else
1013                         if critical_t>0,
1014                             sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))>critical_t);
1015                         else
1016                             sig_chans=find(dat.showing_t(:,plotted_pts(mx_tpt))<critical_t);
1017                         end
1018                     end
1019                     break;
1020                 end
1021             end
1022         end
1023         if size(dat.showingB,1)<=2,
1024             %less than two channels, show channel location
1025             topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1026                 'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
1027             cbar_title='Not Applicable';
1028             cbar_title_fontsize=10;
1029             topo_xtick_labB={' ',' ',' '};
1030         else
1031             if dat.dif(bin),
1032                 %difference between bins, used a fixed color scale
1033                 dat.mx_topoB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1034                 dat.mn_topoB=-dat.mx_topoB;
1035             else
1036                 %non-difference bin, make color scale unique to time point
1037                 dat.mx_topoB=max(dat.showingB(:,plotted_pts(mx_tpt)));
1038                 dat.mn_topoB=min(dat.showingB(:,plotted_pts(mx_tpt)));
1039             end
1040             topoplotMK(dat.showingB(:,plotted_pts(mx_tpt)),dat.chanlocs(dat.showing_chans), ...
1041                 'maplimits',[dat.mn_topoB dat.mx_topoB],'emarker2',{sig_chans,'o',[1 1 1],4});
1042             set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702);
1043             topo_xtick_labB=[dat.mn_topoB 0 dat.mx_topoB];
1044             topo_xtick_labB=round(topo_xtick_labB*100)/100;
1045             if strcmpi(p.Results.stat,'t'),
1046                 cbar_title='t-score';
1047             else
1048                 cbar_title='10*log10(\muV^2/Hz)';
1049             end
1050         end
1051     end
1052     
1053     % COLOR BAR
1054     dat.h_cbarB=axes('position',[0.76 .535 .2 .015]);
1055     cbar(dat.h_cbarB);
1056     set(gca,'xticklabel',topo_xtick_labB);
1057     h_cbar_title=title(cbar_title);
1058     set(h_cbar_title,'fontsize',cbar_title_fontsize);
1059     
1060     % GO BACK 1 FREQUENCY
1061     dat.h_back1=uicontrol(dat.fig_id,...
1062         'CallBack','gui_pow(''back one'');',...
1063         'Units','normalized', ...
1064         'Position',[ 0.80 0.232 0.055 0.04 ],...
1065         'String','<',...
1066         'fontsize',14, ...
1067         'fontunits','normalized', ...
1068         'Tag','back1', ...
1069         'ToolTipString','Show topography at preceding frequency.', ...
1070         'Style','pushbutton');
1071     
1072     % GO FORWARD 1 FREQUENCY
1073     dat.h_forward1=uicontrol(dat.fig_id,...
1074         'CallBack','gui_pow(''forward one'');',...
1075         'Units','normalized', ...
1076         'Position',[ 0.865 0.232 0.055 0.04 ],...
1077         'String','>', ...
1078         'fontsize',14, ...
1079         'fontunits','normalized', ...
1080         'Tag','forward1', ...
1081         'ToolTipString','Show topography at subsequent frequency.', ...
1082         'Style','pushbutton');
1083     
1084     % ANIMATE BACKWARDS IN FREQUENCY
1085     dat.h_back=uicontrol(dat.fig_id,...
1086         'CallBack','gui_pow(''back'');',...
1087         'Units','normalized', ...
1088         'Position',[ 0.735 0.232 0.055 0.04 ],...
1089         'String','<<',...
1090         'fontsize',14, ...
1091         'fontunits','normalized', ...
1092         'Tag','back', ...
1093         'interruptible','on', ...
1094         'ToolTipString','Animate topography going backwards in frequency.', ...
1095         'Style','pushbutton');
1096     
1097     % ANIMATE FORWARDS IN FREQUENCY
1098     dat.h_forward=uicontrol(dat.fig_id,...
1099         'CallBack','gui_pow(''forward'');',...
1100         'Units','normalized', ...
1101         'Position',[ 0.93 0.232 0.055 0.04 ],...
1102         'String','>>',...
1103         'fontsize',14, ...
1104         'fontunits','normalized', ...
1105         'Tag','back', ...
1106         'interruptible','on', ...
1107         'ToolTipString','Animate topography going forwards in frequency.', ...
1108         'Style','pushbutton');
1109     
1110     % STOP ANIMATION
1111     dat.h_stop=uicontrol(dat.fig_id,...
1112         'CallBack','dat=get(gcbf,''userdata''); dat.interrupt=1; set(dat.fig_id,''userdata'',dat);',...
1113         'Units','normalized', ...
1114         'Position',[ 0.745 0.179 0.23 0.05 ],...
1115         'String','Stop Animation',...
1116         'fontsize',14, ...
1117         'fontunits','normalized', ...
1118         'Tag','stop', ...
1119         'enable','off', ...
1120         'ToolTipString','Stop topography animation.', ...
1121         'Style','pushbutton');
1122    
1123 
1124     
1125     %
1126     %%%%%%%%%%%%%%%%%%%%%% AXIS E: PLOTTING OPTIONS %%%%%%%%%%%%%%%%%%%%%%%%
1127     %
1128     
1129     % PANEL
1130     uipanel(dat.fig_id,...
1131         'Units','normalized', ...
1132         'Position',[ 0 0 1 0.178 ],...
1133         'shadowcolor','k', ...
1134         'highlightcolor',frm_col, ...
1135         'foregroundcolor',frm_col, ...
1136         'backgroundcolor',frm_col);
1137       
1138         
1139     %%%% WHICH BIN TO PLOT
1140     bdesc_str=cell(1,n_bin);
1141     for a=1:n_bin,
1142         bdesc_str{a}=sprintf('Bin %d: %s',a,dat.bindesc{a});
1143     end 
1144     % Text
1145     uicontrol(dat.fig_id,...
1146         'Units','normalized', ...
1147         'Position',[ 0.01 0.115 0.2 0.05 ],...
1148         'String','Current Bin',...
1149         'fontsize',12, ...
1150         'ToolTipString','Bin to plot in Frequency x Spectra/t-Score axis.', ...
1151         'Style','text');
1152     % Create bin menu
1153     dat.h_bin=uicontrol(dat.fig_id,...
1154         'CallBack','gui_pow(''change bin'');',...
1155         'Units','normalized', ...
1156         'Position',[ 0.01 0.08 0.24 0.05 ],...
1157         'fontsize',12, ...
1158         'String',bdesc_str, ...
1159         'Value',bin, ...
1160         'Style','popup', ...
1161         'ToolTipString','Bin to plot in Frequency x Spectra/t-Score axis.', ...
1162         'tag','bin');
1163     
1164     
1165     %%%% WHICH T-TESTS RESULTS TO PLOT
1166     ttest_str=cell(1,n_psbl_tests+1);
1167     for a=1:n_psbl_tests,
1168         ttest_str{a}=sprintf('Test %d: Bin %d, Frequencies ',dat.psbl_tests(a),dat.t_tests(a).bin);
1169         n_ttst_wind=size(dat.t_tests(a).freq_band,1);
1170         for b=1:n_ttst_wind,
1171             ttest_str{a}=[ttest_str{a} int2str(dat.t_tests(a).freq_band(b,1)) '-' int2str(dat.t_tests(a).freq_band(b,2)) ','];
1172         end
1173         if length(dat.t_tests(a).crit_t)==2,
1174             ttest_str{a}=[ttest_str{a} ' Two-Tailed,'];
1175         elseif dat.t_tests(a).crit_t<0,
1176             ttest_str{a}=[ttest_str{a} ' Lower-Tailed,'];
1177         else
1178             ttest_str{a}=[ttest_str{a} ' Upper-Tailed,'];
1179         end
1180         
1181         if isnan(dat.t_tests(a).estimated_alpha)
1182             ttest_str{a}=[ttest_str{a} sprintf(' q=%.4f',dat.t_tests(a).desired_alphaORq)];
1183             ttest_str{a}=[ttest_str{a} sprintf(', method=%s',dat.t_tests(a).mult_comp_method)];
1184         else
1185             ttest_str{a}=[ttest_str{a} sprintf(' alpha=%.4f',dat.t_tests(a).estimated_alpha)];
1186         end
1187         
1188         if dat.t_tests(a).null_mean,
1189             ttest_str{a}=[ttest_str{a} sprintf(', Null Mean=%.4f',dat.t_tests(a).null_mean)];
1190         end
1191     end
1192     ttest_str{n_psbl_tests+1}='None/Manual';
1193     
1194     % Text
1195     uicontrol(dat.fig_id,...
1196         'Units','normalized', ...
1197         'Position',[ 0.275 0.115 0.2 0.05 ],...
1198         'String','Current Test Result',...
1199         'fontsize',12, ...
1200         'ToolTipString','Set of t-test results to visualize.', ...
1201         'Style','text');
1202     % Create sortvar browse button
1203     dat.h_ptest=uicontrol(dat.fig_id,...
1204         'CallBack','gui_pow(''change test'');',...
1205         'Units','normalized', ...
1206         'Position',[ 0.26 0.075 0.24 0.055 ],...
1207         'fontsize',12, ...
1208         'String',ttest_str, ...
1209         'Value',crnt_ttest, ...
1210         'Style','popup', ...
1211         'ToolTipString','Set of t-test results to visualize.', ...
1212         'tag','bin');
1213 
1214     %%%  frequency band in which hypotheses tests were done
1215     %Text
1216     uicontrol(dat.fig_id,...
1217         'Units','normalized', ...
1218         'Position',[ 0.505 0.115 0.26 0.05 ],...
1219         'String','Test Band(s) [Min Max]:',...
1220         'fontsize',12, ...
1221         'Style','text');
1222     %Edit Box
1223     wind_edges=[];
1224     for nw=1:dat.n_wind,
1225         if nw==dat.n_wind,
1226             wind_edges=[wind_edges num2str(test_wind(nw,:))];
1227         else
1228             wind_edges=[wind_edges num2str(test_wind(nw,:)) '; ']; 
1229         end
1230     end
1231     dat.h_testwind=uicontrol(dat.fig_id,...
1232         'CallBack','gui_pow(''update dashed lines'');',...
1233         'Units','normalized', ...
1234         'fontsize',12, ...
1235         'BackGroundColor','w', ...
1236         'Position',[ 0.525 0.095 0.22 0.04 ],...
1237         'String',wind_edges, ...
1238         'Style','edit', ...
1239         'ToolTipString','Miniumum and maximum frequency in band in which hypothesis tests were done.', ...
1240         'tag','freqrange'); 
1241     
1242     
1243     %%% Critical t-score here
1244     %Text
1245     uicontrol(dat.fig_id,...
1246         'Units','normalized', ...
1247         'Position',[ 0.76 0.115 0.23 0.05 ],...
1248         'String','Critical t-score(s)',...
1249         'fontsize',12, ...
1250         'Style','text');
1251     %Edit Box
1252     dat.h_critval=uicontrol(dat.fig_id,...
1253         'CallBack','gui_pow(''update critical t'');',...
1254         'Units','normalized', ...
1255         'fontsize',12, ...
1256         'BackGroundColor','w', ...
1257         'Position',[ 0.79 0.09 0.16 0.045 ],...
1258         'String',num2str(critical_t), ...
1259         'Style','edit', ...
1260         'ToolTipString','Critical t-score(s) for reliable deviation from 0 difference between bins.', ...
1261         'tag','freqrange');
1262     
1263     %%%% WHICH STAT TO PLOT
1264     stats={'t-score of spectra','standard error of spectra','root mean spectra squared'};
1265     % Text
1266     uicontrol(dat.fig_id,...
1267         'Units','normalized', ...
1268         'Position',[ 0.01 0.183 0.09 0.03 ],...
1269         'String','Statistic:',...
1270         'fontsize',12, ...
1271         'ToolTipString','Select what to plot in secondary waveform axis: t-scores, standard error of the mean, or root mean squared.', ...
1272         'Style','text');
1273     
1274     if strcmpi(p.Results.stat,'rms') || isinf(dat.t_scores(1,1,bin)) || isnan(dat.t_scores(1,1,bin))
1275         %isinf(dat.t_scores(1,1,bin)) will
1276         %equal 1 if there are insufficient subjects to calculate t-scores
1277         ini_val=3;
1278     elseif strcmpi(p.Results.stat,'t'),
1279         ini_val=1;
1280     elseif strcmpi(p.Results.stat,'stder'),
1281         ini_val=2;
1282     else
1283         close(gcf);
1284         error('Unrecognized value of input argument ''stat''.');
1285     end
1286     dat.h_stat=uicontrol(dat.fig_id,...
1287         'CallBack','gui_pow(''change stat'');',...
1288         'Units','normalized', ...
1289         'Position',[ 0.095 0.165 0.16 0.05 ],...
1290         'fontsize',12, ...
1291         'value',ini_val, ...
1292         'String',stats, ...
1293         'Style','popup', ...
1294         'ToolTipString','Plot spectra t-scores or standard error of the mean in secondary axis?', ...
1295         'tag','stat');
1296     
1297     %%% FREQUENCY RANGE
1298     %Text
1299     uicontrol(dat.fig_id,...
1300         'Units','normalized', ...
1301         'Position',[ 0.01 0.035 0.24 0.05 ],...
1302         'String','Freq Range [Min Max]',...
1303         'fontsize',12, ...
1304         'Style','text');
1305     %Edit Box
1306     dat.h_freqrange=uicontrol(dat.fig_id,...
1307         'CallBack','gui_pow(''new freq limits'');',...
1308         'Units','normalized', ...
1309         'fontsize',12, ...
1310         'BackGroundColor','w', ...
1311         'Position',[ 0.06 0.013 0.11 0.045 ],...
1312         'String',num2str(dat.plt_freqs), ...
1313         'Style','edit', ...
1314         'ToolTipString','Miniumum and maximum frequency on Frequency x Power axis.', ...
1315         'tag','freqrange');   
1316     
1317     %%% POWER SPECTRA RANGE BOX (AXIS A)
1318     %Text
1319     uicontrol(dat.fig_id,...
1320         'Units','normalized', ...
1321         'Position',[ 0.26 0.035 0.26 0.05 ],...
1322         'String','Power Range [Min Max]',...
1323         'HorizontalAlignment','left', ...
1324         'fontsize',12, ...
1325         'Style','text');
1326     %Edit Box
1327     dat.h_statrangeA=uicontrol(dat.fig_id,...
1328         'CallBack','gui_pow(''new statistic limitsA'');',...
1329         'Units','normalized', ...
1330         'fontsize',12, ...
1331         'BackGroundColor','w', ...
1332         'Position',[ 0.28 0.013 0.16 0.045 ],...
1333         'String',num2str(round(vA(3:4)*100)/100), ...
1334         'ToolTipString','Miniumum and maximum power on Frequency x Power axis.', ...
1335         'Style','edit', ...
1336         'tag','statrange'); 
1337     
1338     %%% t-score/StdErr/RMS RANGE BOX (AXIS B)
1339     %Text
1340     uicontrol(dat.fig_id,...
1341         'Units','normalized', ...
1342         'Position',[ 0.50 0.035 0.26 0.05 ],...
1343         'String','t/SE/RMS Range [Min Max]',...
1344         'HorizontalAlignment','left', ...
1345         'fontsize',12, ...
1346         'Style','text');
1347     %Edit Box
1348     dat.h_statrangeB=uicontrol(dat.fig_id,...
1349         'CallBack','gui_pow(''new statistic limitsB'');',...
1350         'Units','normalized', ...
1351         'fontsize',12, ...
1352         'BackGroundColor','w', ...
1353         'Position',[ 0.54 0.013 0.16 0.045 ],...
1354         'String',num2str(round(vB(3:4)*100)/100), ...
1355         'ToolTipString','Miniumum and maximum t-scores/power on Frequency x t-Scores/Standard Error/RMS axis.', ...
1356         'Style','edit', ...
1357         'tag','statrange');   
1358     
1359     % Button to close GUI
1360     uicontrol(dat.fig_id,...
1361         'CallBack','close(gcbf);',...
1362         'Units','normalized', ...
1363         'Position',[ 0.75 0.012 0.11 0.05 ],...
1364         'String','Close',...
1365         'fontsize',12, ...
1366         'Tag','close', ...
1367         'backgroundcolor','m', ...
1368         'ToolTipString','Close GUI', ...
1369         'Style','pushbutton');
1370     
1371     dat.help_msg=sprintf(['Hold mouse cursor over a GUI control for an explanation of what it does.\n\n', ...
1372         'Frequency x power axes visualizes EEG spectral power, t-score of power, standard error of power, or root mean spectra squared simultaneously at multiple electrodes.  ' ... 
1373         'Each colored line corresponds to a different electrode.\n\nClick on Freq x power/t-score/stderr/RMS axis to visualize the scalp topography\n', ...
1374         'at that frequency.\n\nClick on electrodes in scalp topography to see electrode name.\n\n', ...
1375         'This GUI was produced by gui_pow.m']);
1376     
1377     % Button for help
1378     uicontrol(dat.fig_id,...
1379         'CallBack','dat=get(gcbf,''userdata''); helpdlg(dat.help_msg,''POW GUI Help'');', ...
1380         'Units','normalized', ...
1381         'Position',[ 0.87 0.01 0.11 0.05 ],...
1382         'String','Help',...
1383         'fontsize',12, ...
1384         'Tag','help', ...
1385         'ToolTipString','Click for help', ...
1386         'Style','pushbutton');
1387     dat.interrupt=1;
1388     set(dat.fig_id,'userdata',dat);
1389 elseif strcmpi(cmnd_str,'freq jump'),
1390     new_freq=find_tpt(str2num(get(dat.h_topo_freq,'string')), ...
1391         dat.freqs);
1392     if new_freq<dat.start_pt,
1393         errordlg('That frequency is too low.');
1394     elseif new_freq>dat.end_pt,
1395         errordlg('That frequency is too high.');
1396     else
1397         set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1398         set(dat.h_lineA,'XData',[1 1]*dat.freqs(new_freq));
1399         set(dat.h_lineB,'XData',[1 1]*dat.freqs(new_freq));
1400         set(dat.fig_id,'userdata',dat);
1401         bin=get(dat.h_bin,'value');
1402         redraw_topos(dat,~dat.dif(bin)); %if bin is not a difference between other bins, redraw color bar
1403         drawnow;
1404     end    
1405 elseif strcmpi(cmnd_str,'back one'),
1406     current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1407         dat.freqs);
1408     new_freq=current_freq-1;
1409     if new_freq<dat.start_pt,
1410         errordlg('Can''t go back any further.');
1411     else
1412         set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1413         set(dat.h_lineA,'XData',[1 1]*dat.freqs(new_freq));
1414         set(dat.h_lineB,'XData',[1 1]*dat.freqs(new_freq));
1415         set(dat.fig_id,'userdata',dat);
1416         bin=get(dat.h_bin,'value');
1417         redraw_topos(dat,~dat.dif(bin)); %if bin is not a difference between other bins, redraw color bar
1418         drawnow;
1419     end
1420 elseif strcmpi(cmnd_str,'forward one'),
1421     current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1422         dat.freqs);
1423     new_freq=current_freq+1;
1424     if new_freq>dat.end_pt,
1425         errordlg('Can''t go forward any further.');
1426     else
1427         set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1428         set(dat.h_lineA,'XData',[1 1]*dat.freqs(new_freq));
1429         set(dat.h_lineB,'XData',[1 1]*dat.freqs(new_freq));
1430         set(dat.fig_id,'userdata',dat);
1431         bin=get(dat.h_bin,'value');
1432         redraw_topos(dat,~dat.dif(bin)); %if bin is not a difference between other bins, redraw color bar
1433         drawnow;
1434     end
1435 elseif strcmpi(cmnd_str,'back'),
1436     interrupt=0;
1437     dat.interrupt=0;
1438     set(dat.h_stop,'enable','on');
1439     set(dat.h_forward,'enable','off');
1440     set(dat.h_back,'enable','off');
1441     set(dat.h_forward1,'enable','off');
1442     set(dat.h_back1,'enable','off');
1443     set(dat.fig_id,'userdata',dat);
1444     bin=get(dat.h_bin,'value');
1445     redraw_cbar=~dat.dif(bin); %if bin is not a difference between other bins, redraw color bar
1446     drawnow;
1447     current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1448         dat.freqs);
1449     new_freq=current_freq-1;
1450     loop_ct=0;
1451     while (new_freq>=dat.start_pt) && (interrupt~=1),
1452         set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1453         set(dat.h_lineA,'XData',[1 1]*dat.freqs(new_freq));
1454         set(dat.h_lineB,'XData',[1 1]*dat.freqs(new_freq));
1455         drawnow('update');
1456         redraw_topos(dat,redraw_cbar);
1457         drawnow;
1458         new_freq=new_freq-1;
1459         loop_ct=loop_ct+1;
1460         if loop_ct==5,
1461             loop_ct=0;
1462             new_tmp=get(dat.fig_id,'userdata');
1463             interrupt=new_tmp.interrupt;
1464         end
1465     end
1466     drawnow;
1467     dat.interrupt=0;
1468     new_freq=new_freq+1; %undo step that broke loop
1469     set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1470     set(dat.h_stop,'enable','off');
1471     set(dat.h_forward,'enable','on');
1472     set(dat.h_back,'enable','on');
1473     set(dat.h_forward1,'enable','on');
1474     set(dat.h_back1,'enable','on');
1475     set(dat.fig_id,'userdata',dat);
1476 elseif strcmpi(cmnd_str,'forward'),
1477     interrupt=0;
1478     dat.interrupt=0;
1479     set(dat.h_stop,'enable','on');
1480     set(dat.h_forward,'enable','off');
1481     set(dat.h_back,'enable','off');
1482     set(dat.h_forward1,'enable','off');
1483     set(dat.h_back1,'enable','off');
1484     set(dat.fig_id,'userdata',dat);
1485     bin=get(dat.h_bin,'value');
1486     redraw_cbar=~dat.dif(bin); %if bin is not a difference between other bins, redraw color bar
1487     drawnow;
1488     current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1489         dat.freqs);
1490     new_freq=current_freq+1;
1491     loop_ct=0;
1492     while (new_freq<=dat.end_pt) && (interrupt~=1),
1493         set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1494         set(dat.h_lineA,'XData',[1 1]*dat.freqs(new_freq));
1495         set(dat.h_lineB,'XData',[1 1]*dat.freqs(new_freq));
1496         drawnow('update');
1497         redraw_topos(dat,redraw_cbar);
1498         drawnow;
1499         new_freq=new_freq+1;
1500         loop_ct=loop_ct+1;
1501         if loop_ct==5,
1502             loop_ct=0;
1503             new_tmp=get(dat.fig_id,'userdata');
1504             interrupt=new_tmp.interrupt;
1505         end
1506     end
1507     drawnow;
1508     dat.interrupt=0;
1509     new_freq=new_freq-1; %undo step that broke loop
1510     set(dat.h_topo_freq,'string',num2str(dat.freqs(new_freq)));
1511     set(dat.h_stop,'enable','off');
1512     set(dat.h_forward,'enable','on');
1513     set(dat.h_back,'enable','on');
1514     set(dat.h_forward1,'enable','on');
1515     set(dat.h_back1,'enable','on');
1516     set(dat.fig_id,'userdata',dat);
1517 elseif strcmpi(cmnd_str,'change stat'),
1518     stat=get(dat.h_stat,'value');
1519     current_bin=get(dat.h_bin,'value');
1520     if (stat~=3),
1521         %make sure there are sufficients subjects for that bin
1522         if isinf(dat.t_scores(1,1,current_bin)) || isnan(dat.t_scores(1,1,current_bin)) 
1523             stat=3;
1524             set(dat.h_stat,'value',stat);
1525             if (stat==2)
1526                 warndlg('Only one participant contributed to this bin. Thus the grand average standard error cannot be esimated.','gui_pow Warning');
1527             else
1528                 warndlg('Only one participant contributed to this bin. Thus the grand average t-scores cannot be derived.','gui_pow Warning');
1529             end
1530         end
1531     end
1532         
1533     if (stat==1),
1534         % t-scores
1535         if ~isempty(dat.h_crit1),
1536             delete(dat.h_crit1);
1537         end
1538         if ~isempty(dat.h_crit2),
1539             delete(dat.h_crit2);
1540         end
1541         dat.h_crit1=[];
1542         dat.h_crit2=[];
1543         
1544         if ~isempty(dat.h_alph1),
1545             delete(dat.h_alph1);
1546         end
1547         if ~isempty(dat.h_alph2),
1548             delete(dat.h_alph2);
1549         end
1550         dat.h_alph1=[];
1551         dat.h_alph2=[];
1552     end
1553     
1554     %redraw freq plot
1555     draw_waveforms(dat,0);
1556     gui_pow('update dashed lines'); %also redraws topo
1557 elseif strcmpi(cmnd_str,'change bin'),
1558     new_bin=get(dat.h_bin,'value');
1559     crnt_ttest_id=get(dat.h_ptest,'value');
1560     n_t_tests=length(dat.t_tests);
1561     if (crnt_ttest_id==(n_t_tests+1)) || (dat.t_tests(crnt_ttest_id).bin~=new_bin),
1562         % If currently selected set of t-tests is for a different bin
1563         % than is currently visualized search for a t-test set on
1564         % this bin. Use the first test if more than one test has
1565         % been performed on the bin.  If no test is
1566         % found, set to None/Manual.
1567         crnt_ttest_id=n_t_tests+1;
1568         for a=1:n_t_tests,
1569             if dat.t_tests(a).bin==new_bin;
1570                 crnt_ttest_id=a;
1571                 break;
1572             end
1573         end
1574         set(dat.h_ptest,'value',crnt_ttest_id);
1575         dat=update_test(dat);
1576     end
1577     draw_waveforms(dat,1);
1578     gui_pow('update dashed lines'); %also redraws topo plot
1579 elseif strcmpi(cmnd_str,'new freq limits'),
1580     %frequency limits
1581     plotted_freqs=dat.freqs(dat.start_pt:dat.end_pt);
1582     freq_lim=str2num(get(dat.h_freqrange,'string'));
1583     if length(freq_lim)~=2,
1584         errordlg('Enter exactly two values for frequency range (desired Min and Max values).','gui_pow Error');
1585         set(dat.h_freqrange,'string',num2str([plotted_freqs(1) plotted_freqs(end)])); %reset frequency limits
1586     elseif freq_lim(2)<freq_lim(1),
1587         errordlg('The frequency range value must be greater than the first (enter desired Min then Max).','gui_pow Error');
1588         set(dat.h_freqrange,'string',num2str([plotted_freqs(1) plotted_freqs(end)])); %reset frequency  limits
1589     elseif (freq_lim(1)<dat.freqs(1)) || (freq_lim(2)>dat.freqs(end))
1590         errordlg(sprintf('Frequency range values must be between %d and %d Hz.',dat.freqs(1),dat.freqs(end)),'gui_pow Error');
1591         set(dat.h_freqrange,'string',num2str([plotted_freqs(1) plotted_freqs(end)])); %reset frequency limits
1592     else
1593         %change frequency limits
1594         set(dat.h_freqA,'xlim',freq_lim);
1595         set(dat.h_freqB,'xlim',freq_lim);
1596         dat.start_pt=find_tpt(freq_lim(1),dat.freqs);
1597         dat.end_pt=find_tpt(freq_lim(2),dat.freqs);
1598         
1599         %update max abs val
1600         dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt)))); 
1601         dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1602         current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1603             dat.freqs);
1604         if (current_freq>dat.end_pt) || (current_freq<dat.start_pt)
1605            % Frequency whose topography is currently being visualized
1606            % falls outside of frequency range.  Reset current frequency to peak
1607            % RMS latency within visualized frequency band.
1608            bin=get(dat.h_bin,'value');
1609            [dummy, mx_tpt]=max(dat.rms(dat.start_pt:dat.end_pt,bin));
1610            showing_pts=dat.start_pt:dat.end_pt;
1611            set(dat.h_lineA,'xdata',[1 1]*dat.freqs(showing_pts(mx_tpt)));
1612            set(dat.h_lineB,'xdata',[1 1]*dat.freqs(showing_pts(mx_tpt)));
1613            
1614            set(dat.h_topo_freq,'string',num2str(dat.freqs(showing_pts(mx_tpt))));
1615         end
1616         
1617         redraw_topos(dat,1);
1618         set(dat.fig_id,'userdata',dat);
1619     end
1620 elseif strcmpi(cmnd_str,'new statistic limitsA'),
1621     %statistic limits
1622     plotted_limits=get(dat.h_freqA,'ylim');
1623     new_lim=str2num(get(dat.h_statrangeA,'string'));
1624     if length(new_lim)~=2,
1625         errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_pow Error');
1626         set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
1627     elseif new_lim(2)<new_lim(1),
1628         errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_pow Error');
1629         set(dat.h_statrangeA,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
1630     else
1631         %change frequency line limits
1632         set(dat.h_freqA,'ylim',new_lim);
1633         set(dat.h_lineA,'YData',new_lim); %adjust current frequency line
1634         
1635         %change dashed frequency line limits (hypothesis test window)
1636         if ~isempty(dat.h_wind1A)
1637            set(dat.h_wind1A,'YData',new_lim); 
1638            set(dat.h_wind2A,'YData',new_lim);
1639         end
1640     end
1641 elseif strcmpi(cmnd_str,'new statistic limitsB'),
1642     %statistic limits
1643     plotted_limits=get(dat.h_freqB,'ylim');
1644     new_lim=str2num(get(dat.h_statrangeB,'string'));
1645     if length(new_lim)~=2,
1646         errordlg('Enter exactly two values for statistic range (desired Min and Max values).','gui_pow Error');
1647         set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
1648     elseif new_lim(2)<new_lim(1),
1649         errordlg('The second statistic range value must be greater than the first (enter desired Min then Max).','gui_pow Error');
1650         set(dat.h_statrangeB,'string',num2str([plotted_limits(1) plotted_limits(end)])); %reset statistic limits
1651     else
1652         %change frequency line limits
1653         set(dat.h_freqB,'ylim',new_lim);
1654         set(dat.h_lineB,'YData',new_lim); %adjust current frequency pt line
1655         
1656         %change dashed frequency line limits (hypothesis test window)
1657         if ~isempty(dat.h_wind1B)
1658             set(dat.h_wind1B,'YData',new_lim);
1659             set(dat.h_wind2B,'YData',new_lim);
1660         end
1661     end
1662 elseif strcmpi(cmnd_str,'redraw topo'),
1663     redraw_topos(dat,1); %we need this command string for buttdownfcn calls
1664 elseif strcmpi(cmnd_str,'update dashed lines'),
1665     test_wind=str2num(get(dat.h_testwind,'string'));
1666     
1667     if (size(test_wind,2)>2) || (isempty(test_wind) && ~isempty(get(dat.h_testwind,'string')))
1668         errordlg('Enter pairs of values for frequency band range (desired Min and Max values) or leave box blank. Separate multiple pairs with semicolons.', ...
1669             'gui_pow Error');
1670     elseif length(dat.critical_t)>2,
1671         errordlg('Enter one (for one-tailed test) or two (for two-tailed test) value(s) for critical t-scores or leave box blank.', ...
1672             'gui_pow Error');
1673     else
1674         if isempty(test_wind),
1675             test_wind=[NaN NaN];
1676         end
1677         
1678         % remove existing critical value markers & test frequency band markers
1679         if ~isempty(dat.h_crit1),
1680             delete(dat.h_crit1);
1681         end
1682         if ~isempty(dat.h_crit2),
1683             delete(dat.h_crit2);
1684         end
1685         if ~isempty(dat.h_alph1),
1686             delete(dat.h_alph1);
1687         end
1688         if ~isempty(dat.h_alph2),
1689             delete(dat.h_alph2);
1690         end
1691         if ~isempty(dat.h_wind1A),
1692             delete(dat.h_wind1A);
1693         end
1694         if ~isempty(dat.h_wind2A),
1695             delete(dat.h_wind2A);
1696         end
1697         if ~isempty(dat.h_wind1B),
1698             delete(dat.h_wind1B);
1699         end
1700         if ~isempty(dat.h_wind2B),
1701             delete(dat.h_wind2B);
1702         end
1703         dat.h_wind1A=[];
1704         dat.h_wind2A=[];
1705         dat.h_wind1B=[];
1706         dat.h_wind2B=[];
1707         dat.h_crit1=[];
1708         dat.h_crit2=[];
1709         dat.h_alph1=[];
1710         dat.h_alph2=[];
1711         dat.n_wind=size(test_wind,1);
1712         
1713         if ~sum(isnan(test_wind))
1714             y_rngA=get(dat.h_freqA,'YLim');
1715             y_rngB=get(dat.h_freqB,'YLim');
1716             
1717             axes(dat.h_freqA); %warning message says that I should give axes an output to speed it up, but axes doesn't produce an output
1718             for nw=1:dat.n_wind,
1719                 dat.h_wind1A(nw)=plot([1 1]*test_wind(nw,1),y_rngA,'k--');
1720                 set(dat.h_wind1A(nw),'linewidth',2);
1721                 dat.h_wind2A(nw)=plot([1 1]*test_wind(nw,2),y_rngA,'k--');
1722                 set(dat.h_wind2A(nw),'linewidth',2);
1723             end
1724             
1725             axes(dat.h_freqB);
1726             for nw=1:dat.n_wind,
1727                 dat.h_wind1B(nw)=plot([1 1]*test_wind(nw,1),y_rngB,'k--');
1728                 set(dat.h_wind1B(nw),'linewidth',2);
1729                 dat.h_wind2B(nw)=plot([1 1]*test_wind(nw,2),y_rngB,'k--');
1730                 set(dat.h_wind2B(nw),'linewidth',2);
1731             end
1732             
1733             %Find out if visualized units are microvolts^2/Hz or t-scores
1734             stat=get(dat.h_stat,'value');
1735             
1736             % if stat=1, t-scores, else data are in microvolts^2/Hz (for stderr)
1737             if ~sum(isnan(dat.critical_t)) && (stat==1) && ~isempty(dat.critical_t)
1738                 for nw=1:dat.n_wind,
1739                     dat.h_crit1(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(1),'r--');
1740                     set(dat.h_crit1(nw),'linewidth',3);
1741                     if nw==1,
1742                         %write alpha value on figure
1743                         tm_rng=dat.freqs(end)-dat.freqs(1);
1744                         if strcmpi(dat.mltplcmp_crct,'fdr')
1745                             dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1746                                 ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1747                         else
1748                             dat.h_alph1=text(test_wind(nw,1)-tm_rng*.02,dat.critical_t(1), ...
1749                                 ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1750                         end
1751                         set(dat.h_alph1,'color','r','fontweight','normal','fontsize',12, ...
1752                             'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1753                             'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1754                     end
1755                     if length(dat.critical_t)>1,
1756                         dat.h_crit2(nw)=plot(test_wind(nw,:),[1 1]*dat.critical_t(2),'r--');
1757                         set(dat.h_crit2(nw),'linewidth',3);
1758                         if nw==1,
1759                             %write alpha value on figure
1760                             if strcmpi(dat.mltplcmp_crct,'fdr')
1761                                 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1762                                     ['q=' num2str(rnd_orderofmag(dat.alpha))]);
1763                             else
1764                                 dat.h_alph2=text(test_wind(1)-tm_rng*.02,dat.critical_t(2), ...
1765                                     ['\alpha=' num2str(rnd_orderofmag(dat.alpha))]);
1766                             end
1767                             set(dat.h_alph2,'color','r','fontweight','normal','fontsize',12, ...
1768                                 'horizontalalignment','right','backgroundcolor',[1 1 1], ...
1769                                 'edgecolor',[1 1 1]*.3,'clipping','on','fontname','fixedwidth');
1770                         end
1771                     end
1772                 end
1773             end
1774         end
1775         set(dat.fig_id,'userdata',dat);
1776         redraw_topos(dat,1);
1777     end
1778 elseif strcmpi(cmnd_str,'update critical t'),
1779     critical_t=str2num(get(dat.h_critval,'string'));
1780     if ~isequal(sort(critical_t),sort(dat.critical_t)),
1781         new_alpha=[];
1782         while isempty(new_alpha),
1783             new_alpha=inputdlg({'Enter alpha level for new critical t-score(s)'}, ...
1784                 'Set New Alpha Level',1,{num2str(dat.alpha)});
1785             new_alpha=str2num(new_alpha{1});
1786             if isempty(new_alpha),
1787                 errrodlg('You must enter a numeric value for the new alpha level','gui_pow Error');
1788             end
1789         end
1790         dat.alpha=new_alpha;
1791         dat.critical_t=critical_t;
1792     end
1793     set(dat.fig_id,'userdata',dat);
1794     gui_pow('update dashed lines');
1795 elseif strcmpi(cmnd_str,'change test'),
1796     [dat, redraw_wform]=update_test(dat);    
1797     if redraw_wform,
1798         draw_waveforms(dat,1);
1799     end
1800     gui_pow('update dashed lines'); %also redraws topo
1801 else
1802     errordlg(sprintf('Command "%s" not recognized by gui_pow.m',cmnd_str), ...
1803         'gui_pow Error');
1804 end
1805 
1806 
1807 function draw_waveforms(dat,redrawA)
1808 % Redraws the channel waveforms (i.e., power spectra, t-scores of spectra, standard error of spectra, or RMS of spectra)
1809 % and the color bar the topography.
1810 %
1811 % Used by: 'change bin', 'change stat', and 'change test'
1812 %
1813 % Input:
1814 %   dat     - The userdata of the GUI
1815 %   redrawA - If non-zero, axis A (the power spectra waveformss) will also be redrawn
1816 
1817 new_bin=get(dat.h_bin,'value');
1818 stat=get(dat.h_stat,'value');
1819 crnt_ttest_id=get(dat.h_ptest,'value');
1820 n_t_tests=length(dat.t_tests);
1821 if crnt_ttest_id==n_t_tests+1,
1822     %no t-test results visualized
1823     dat.showing_chans=dat.loaded_chans;
1824 else
1825     dat.showing_chans=intersect(dat.t_tests(crnt_ttest_id).used_chan_ids, ...
1826         dat.loaded_chans);
1827 end
1828 
1829 %redraw Axis B frequency plot
1830 axes(dat.h_freqB);
1831 delete(dat.h_showingB);
1832 delete(dat.h_lineB);
1833 plotted_freqs=dat.freqs(dat.start_pt:dat.end_pt);
1834 %store t-scores for waveform that will be shown
1835 if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1836     %The mean of the null hypothesis is non-zero
1837     dat.showing_t=squeeze( (dat.spec(dat.showing_chans,:,new_bin)- ...
1838         dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1839 else
1840     dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1841 end
1842 
1843 if (stat==1),
1844     %t-score
1845     dat.showingB=dat.showing_t;
1846     cbar_title='t-score';
1847     ylab='t-score';
1848     if dat.dif(new_bin)
1849         dat.h_db_zeroB=plot([dat.freqs(1) dat.freqs(end)],[0 0],'k'); % Power=0 line, only draw for difference bins
1850         hold on;
1851     elseif ~isempty(dat.h_db_zeroB)
1852         delete(dat.h_db_zeroB);
1853         dat.h_db_zeroB=[];
1854     end
1855 elseif (stat==2),
1856     %stder
1857     dat.showingB=squeeze(dat.stder(dat.showing_chans,:,new_bin));
1858     cbar_title='10*log10(\muV^2/Hz)';
1859     ylab='10*log10(\muV^2/Hz) (StdEr)';
1860     if ~isempty(dat.h_db_zeroB)
1861         delete(dat.h_db_zeroB);
1862         dat.h_db_zeroB=[];
1863     end
1864 elseif (stat==3),
1865     %RMS
1866     dat.showingB=dat.rms(:,new_bin)';
1867     cbar_title='Not Applicable';
1868     ylab='\muV/sqrt(Hz) (RMS)';
1869     if ~isempty(dat.h_db_zeroB)
1870         delete(dat.h_db_zeroB);
1871         dat.h_db_zeroB=[];
1872     end
1873 end
1874 if size(dat.showingB,1)==1,
1875     %only one channel being plot
1876     dat.h_showingB=plot(dat.freqs,dat.showingB);
1877     cbar_title='Not Applicable';
1878     cbar_title_fontsize=10;
1879 else
1880     dat.h_showingB=plot(dat.freqs,dat.showingB');
1881     cbar_title_fontsize=14;
1882 end
1883 set(dat.h_freq_ylabB,'string',ylab);
1884 
1885 stat_mx=max(max(dat.showingB));
1886 stat_mn=min(min(dat.showingB));
1887 stat_rng=stat_mx-stat_mn;
1888 stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1889 stat_plt_rng=round(stat_plt_rng*100)/100;
1890 axis([plotted_freqs(1) plotted_freqs(end) stat_plt_rng]);
1891 set(dat.h_statrangeB,'string',num2str(stat_plt_rng));
1892 current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1893     dat.freqs);
1894 h_lineB=plot([1 1]*dat.freqs(current_freq),stat_plt_rng,'k');
1895 set(h_lineB,'linewidth',2);
1896 dat.h_lineB=h_lineB;
1897 
1898 bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1899     'dat=get(gcbf, ''userdata'');' ...
1900     'new_freq=find_tpt(tmppos(1,1),dat.freqs);' ...
1901     'set(dat.h_lineA,''XData'',[1 1]*dat.freqs(new_freq));' ...
1902     'set(dat.h_lineB,''XData'',[1 1]*dat.freqs(new_freq));' ...
1903     'set(dat.h_topo_freq,''string'',num2str(dat.freqs(new_freq)));' ...
1904     'set(dat.fig_id,''userdata'',dat);' ...
1905     'gui_pow(''redraw topo'');' ...
1906     'drawnow;' ...
1907     'clear latpoint dattmp tmppos;' ...
1908     ];
1909 set(dat.h_showingB,'ButtonDownFcn',bdf_code);
1910 set(dat.h_freqB,'ButtonDownFcn',bdf_code);
1911 
1912 %redraw topo color bar for Axis B
1913 dat.absmxB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
1914 axes(dat.h_cbarB);
1915 cla;
1916 cbar(dat.h_cbarB);
1917 absmx=round(dat.absmxB*100)/100;
1918 set(gca,'xticklabel',[-absmx 0 absmx]);
1919 h_cbar_title=title(cbar_title);
1920 set(h_cbar_title,'fontsize',cbar_title_fontsize);
1921 
1922 if redrawA,
1923     %redraw Axis A frequency  plot
1924     new_title=['Bin ' int2str(new_bin) ': ' dat.bindesc{new_bin}];
1925     title_max_char=43;
1926     if length(new_title)>title_max_char,
1927         new_title=new_title(1:title_max_char);
1928     end
1929     set(dat.h_freq_title,'string',new_title);
1930     
1931     
1932     %redraw Axis A frequency  plot
1933     axes(dat.h_freqA);
1934     delete(dat.h_showingA);
1935     delete(dat.h_lineA);
1936     plotted_freqs=dat.freqs(dat.start_pt:dat.end_pt);
1937     if dat.dif(new_bin)
1938         dat.h_db_zeroA=plot([dat.freqs(1) dat.freqs(end)],[0 0],'k'); % Power=0 line, only draw for difference bins
1939     else
1940         if ~isempty(dat.h_db_zeroA)
1941             delete(dat.h_db_zeroA);
1942             dat.h_db_zeroA=[];
1943         end
1944     end
1945     hold on;
1946     
1947     %store t-scores for waveform that will be shown
1948     if (crnt_ttest_id<=n_t_tests) && dat.t_tests(crnt_ttest_id).null_mean
1949         %The mean of the null hypothesis is non-zero
1950         dat.showing_t=squeeze( (dat.spec(dat.showing_chans,:,new_bin)- ...
1951             dat.t_tests(crnt_ttest_id).null_mean)./dat.stder(dat.showing_chans,:,new_bin) );
1952     else
1953         dat.showing_t=squeeze(dat.t_scores(dat.showing_chans,:,new_bin));
1954     end
1955     
1956     dat.showingA=squeeze(dat.spec(dat.showing_chans,:,new_bin));
1957     cbar_title='10*log10(\muV^2/Hz)';
1958     ylab='10*log10(\muV^2/Hz)';
1959     if size(dat.showingA,1)==1,
1960         %only one channel being plot
1961         dat.h_showingA=plot(dat.freqs,dat.showingA);
1962         cbar_title='Not Applicable';
1963         cbar_title_fontsize=10;
1964     else
1965         dat.h_showingA=plot(dat.freqs,dat.showingA');
1966     end
1967     set(dat.h_freq_ylabA,'string',ylab);
1968     
1969     stat_mx=max(max(dat.showingA));
1970     stat_mn=min(min(dat.showingA));
1971     stat_rng=stat_mx-stat_mn;
1972     stat_plt_rng=[stat_mn-stat_rng*.02 stat_mx+stat_rng*.02];
1973     stat_plt_rng=round(stat_plt_rng*100)/100;
1974     axis([plotted_freqs(1) plotted_freqs(end) stat_plt_rng]);
1975     set(dat.h_statrangeA,'string',num2str(stat_plt_rng));
1976     current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
1977         dat.freqs);
1978     h_lineA=plot([1 1]*dat.freqs(current_freq),stat_plt_rng,'k');
1979     set(h_lineA,'linewidth',2);
1980     dat.h_lineA=h_lineA;
1981     
1982     bdf_code = [ 'tmppos = get(gca, ''currentpoint'');' ...
1983         'dat=get(gcbf, ''userdata'');' ...
1984         'new_freq=find_tpt(tmppos(1,1),dat.freqs);' ...
1985         'set(dat.h_lineA,''XData'',[1 1]*dat.freqs(new_freq));' ...
1986         'set(dat.h_lineB,''XData'',[1 1]*dat.freqs(new_freq));' ...
1987         'set(dat.h_topo_freq,''string'',num2str(dat.freqs(new_freq)));' ...
1988         'set(dat.fig_id,''userdata'',dat);' ...
1989         'gui_pow(''redraw topo'');' ...
1990         'drawnow;' ...
1991         'clear latpoint dattmp tmppos;' ...
1992         ];
1993     set(dat.h_freqA,'ButtonDownFcn',bdf_code);
1994     set(dat.h_showingA,'ButtonDownFcn',bdf_code);
1995     
1996     %redraw topo color bar for Axis A
1997     dat.absmxA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
1998     axes(dat.h_cbarA);
1999     cla;
2000     cbar(dat.h_cbarA);
2001     absmx=round(dat.absmxA*100)/100;
2002     set(gca,'xticklabel',[-absmx 0 absmx]);
2003     h_cbar_title=title(cbar_title);
2004     set(h_cbar_title,'fontsize',cbar_title_fontsize);
2005 end
2006 
2007 set(dat.fig_id,'userdata',dat);
2008 
2009 %note, redraw_topos is called by update dashed lines
2010 
2011 
2012 
2013 function [dat, redraw_wform]=update_test(dat)
2014 % Updates the t-test results paramters (e.g., critical t-score)
2015 % Used by: 'change test' & 'change bin'
2016 %
2017 % Inputs:
2018 %   dat - The userdata of the GUI
2019 %
2020 % Outputs:
2021 %   dat            - The revised of the GUI
2022 %   redraw_wform   - 1 if the waveforms in the GUI need to be redrawn
2023 %                    (e.g., if the bin being visualized has changed),
2024 %                    otherwise it's 0
2025 %
2026 
2027 crnt_ttest=get(dat.h_ptest,'value');
2028 
2029 n_psbl_tests=length(dat.psbl_tests);
2030 crnt_bin=get(dat.h_bin,'value');
2031 redraw_wform=0;
2032 if n_psbl_tests<crnt_ttest,
2033     %manual/no test, remove all test info/visualizations
2034     set(dat.h_testwind,'string',[]); %get rid of test wind
2035     dat.alpha=[];
2036     dat.critical_t=[];
2037     dat.mltplcmp_crct=[];
2038     set(dat.h_critval,'string',[]);
2039     
2040     if ~isequal(dat.loaded_chans,dat.showing_chans)
2041         redraw_wform=1;
2042     end    
2043 else
2044     ptest_bin=dat.t_tests(crnt_ttest).bin;
2045     if ptest_bin~=crnt_bin,
2046         redraw_wform=1;
2047         set(dat.h_bin,'value',ptest_bin);
2048     end
2049     
2050     %If the mean of the null hypothesis of the previously shown test
2051     %results differs from that of the new test results, redraw the waveform
2052     crnt_null_mean=dat.null_mean;
2053     if crnt_null_mean~=dat.t_tests(crnt_ttest).null_mean,
2054         redraw_wform=1;
2055     end
2056     dat.null_mean=dat.t_tests(crnt_ttest).null_mean;
2057     
2058     %test  frequency band(s)
2059     test_wind=dat.t_tests(crnt_ttest).freq_band;
2060     dat.n_wind=size(test_wind,1);
2061     wind_edges=[];
2062     for nw=1:dat.n_wind,
2063         if nw==dat.n_wind,
2064             wind_edges=[wind_edges num2str(test_wind(nw,:))];
2065         else
2066             wind_edges=[wind_edges num2str(test_wind(nw,:)) '; '];
2067         end
2068     end
2069     set(dat.h_testwind,'string',wind_edges);
2070     
2071     % if test was performed including channels that are not currently
2072     % loaded, throw a warning
2073     if ~isempty(setdiff(dat.t_tests(crnt_ttest).used_chan_ids, ...
2074             dat.loaded_chans)),
2075         warndlg('The set of t-tests you selected includes some channels that were excluded when you created this GUI.  Keep this in mind when interpreting the visualization.','gui_pow Warning');
2076     end
2077     
2078     % if test was performed on a set of channels that differs from what
2079     % is currently shown, replot the data with the 'change bin' command
2080     if ~isequal(dat.t_tests(crnt_ttest).used_chan_ids,dat.showing_chans)
2081         redraw_wform=1;
2082     end
2083     
2084     % set critical values and alpha level
2085     if isnan(dat.t_tests(crnt_ttest).estimated_alpha)
2086         dat.alpha=dat.t_tests(crnt_ttest).desired_alphaORq;
2087         dat.mltplcmp_crct='fdr';
2088     else
2089         dat.alpha=dat.t_tests(crnt_ttest).estimated_alpha;
2090         dat.mltplcmp_crct='perm';
2091     end
2092     dat.critical_t=dat.t_tests(crnt_ttest).crit_t;
2093     set(dat.h_critval,'string',num2str(dat.critical_t));
2094 end
2095 set(dat.fig_id,'userdata',dat);
2096 
2097 
2098 function redraw_topos(dat,redraw_cbars)
2099 
2100 current_freq=find_tpt(str2double(get(dat.h_topo_freq,'string')), ...
2101     dat.freqs);
2102 
2103 test_wind=str2num(get(dat.h_testwind,'string'));
2104 critical_t=str2num(get(dat.h_critval,'string'));
2105 
2106 if ~isempty(test_wind) && ~isempty(critical_t),
2107     n_showing=length(dat.showing_chans);
2108     sig_chans=zeros(1,n_showing);
2109     
2110     %if current frequency is in a test window look for channels with
2111     %sig effects
2112     for nw=1:dat.n_wind,
2113         if (dat.freqs(current_freq)>=test_wind(nw,1)) && (dat.freqs(current_freq)<=test_wind(nw,2)),
2114             if length(critical_t)==2,
2115                 sig_chans(dat.showing_t(:,current_freq)>max(critical_t))=1;
2116                 sig_chans(dat.showing_t(:,current_freq)<min(critical_t))=1;
2117             else
2118                 if critical_t>0,
2119                     sig_chans(dat.showing_t(:,current_freq)>critical_t)=1;
2120                 else
2121                     sig_chans(dat.showing_t(:,current_freq)<critical_t)=1;
2122                 end
2123             end
2124             break;
2125         end
2126     end
2127     sig_chans=find(sig_chans>0);
2128 else
2129     sig_chans=[];
2130 end
2131 
2132 % SPECTRA TOPO
2133 set(dat.fig_id,'CurrentAxes',dat.h_topoA); %<-changes current axis without updating GUI graphics
2134 %which is why I use this instead of axes(dat.h_topoA)
2135 if size(dat.showingA,1)<=2,
2136     %two or fewer channels, we can only plot electrode locations
2137     topoplotMK(dat.showingA(:,current_freq),dat.chanlocs(dat.showing_chans), ...
2138         'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2139     %For some reason, when only electrode is plot you need to put a numeric value as the first argument for topoplotMK
2140     %But when there are multiple electrodes, you need to pass multiple
2141     %values
2142     
2143     topo_xtick_labA={' ',' ',' '};
2144     topo_xtick_labB={' ',' ',' '};
2145     
2146     if get(dat.h_stat,'value')==3,
2147         %RMS topo
2148         if redraw_cbars,
2149             %statistic has been changed, need to erase old topo in B topo
2150             %axis
2151             set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2152             topoplotMK(dat.showingA(:,current_freq),dat.chanlocs(dat.showing_chans), ...
2153                 'style','blank','plain_blank',1);
2154         end
2155     else
2156         % t-score/stderr
2157         set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2158         topoplotMK(dat.showingB(:,current_freq),dat.chanlocs(dat.showing_chans), ...
2159             'style','blank','plain_blank',1,'emarker2',{sig_chans,'o',[1 1 1],4});
2160     end
2161 else
2162     bin=get(dat.h_bin,'value');
2163     if dat.dif(bin),
2164         %difference between bins, used a fixed color scale
2165         dat.mx_topoA=max(max(abs(dat.showingA(:,dat.start_pt:dat.end_pt))));
2166         dat.mn_topoA=-dat.mx_topoA;
2167         dat.mx_topoB=max(max(abs(dat.showingB(:,dat.start_pt:dat.end_pt))));
2168         dat.mn_topoB=-dat.mx_topoB;
2169     else
2170         %non-difference bin, make color scale unique to time point
2171         %dat.mx_topoA=max(abs(dat.showingA(:,plotted_pts(current_freq))));
2172         dat.mx_topoA=max(max(dat.showingA(:,current_freq)));
2173         dat.mn_topoA=min(min(dat.showingA(:,current_freq)));
2174         dat.mx_topoB=max(max(dat.showingB(:,current_freq)));
2175         dat.mn_topoB=min(min(dat.showingB(:,current_freq)));
2176     end
2177     topo_xtick_labA=[dat.mn_topoA 0 dat.mx_topoA];
2178     topo_xtick_labA=round(topo_xtick_labA*100)/100;
2179     topo_xtick_labB=[dat.mn_topoB 0 dat.mx_topoB];
2180     topo_xtick_labB=round(topo_xtick_labB*100)/100;
2181     topoplotMK(dat.showingA(:,current_freq),dat.chanlocs(dat.showing_chans),'maplimits', ...
2182         [dat.mn_topoA dat.mx_topoA],'emarker2',{sig_chans,'o',[1 1 1],4});
2183     set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702); %make topoplot background color match that of GUI
2184     
2185     if get(dat.h_stat,'value')==3,
2186         %RMS topo
2187         if redraw_cbars,
2188             %statistic has been changed, need to erase old topo
2189             set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2190             topoplotMK([],dat.chanlocs(dat.showing_chans), ...
2191                 'style','blank','plain_blank',1);
2192             %For some reason, when only electrode is plot you need to put a numeric value as the first argument for topoplotMK
2193             %But when there are multiple electrodes, you need to pass multiple
2194             %values
2195             topo_xtick_labB={' ',' ',' '};
2196             set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702); %make topoplot background color match that of GUI
2197         end
2198     else
2199         % t-score/stderr
2200         set(dat.fig_id,'CurrentAxes',dat.h_topoB);
2201         topoplotMK(dat.showingB(:,current_freq),dat.chanlocs(dat.showing_chans),'maplimits', ...
2202             [dat.mn_topoB dat.mx_topoB],'emarker2',{sig_chans,'o',[1 1 1],4});
2203         set(findobj(gca,'type','patch'),'facecolor',[1 1 1]*.702); %make topoplot background color match that of GUI
2204     end
2205 end
2206 
2207 if (redraw_cbars)
2208     % SPECTRA COLOR BAR TICK LABELS
2209     %axes(dat.h_cbarA);
2210     set(dat.fig_id,'CurrentAxes',dat.h_cbarA);
2211     set(gca,'xticklabel',topo_xtick_labA);
2212     
2213     % t-Score/StdErr/RMS COLOR BAR TICK LABELS
2214     %axes(dat.h_cbarB);
2215     set(dat.fig_id,'CurrentAxes',dat.h_cbarB);
2216     B_stat=get(dat.h_stat,'value');
2217     if B_stat==1,
2218         %t-score
2219         cbar_title='t-score';
2220         cbar_title_fontsize=14;
2221     elseif B_stat==3,
2222         %RMS
2223         cbar_title='Not Applicable';
2224         cbar_title_fontsize=10;
2225     else
2226         %stder
2227         cbar_title='10*log10(\muV^2/Hz)';
2228         cbar_title_fontsize=14;
2229     end
2230     
2231     set(gca,'xticklabel',topo_xtick_labB);
2232     set(get(gca,'title'),'string',cbar_title,'fontsize',cbar_title_fontsize);
2233 end
2234 drawnow
2235

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