plot_erpimageMK() - Produces an ERPimage from variables generated by compile_erpimageMK.m using EEGLAB function erpimage.m Usage: >> plot_erpimageMK(chan,sort_var,varargin) Required Inputs: chan = [string] Name of electrode to plot (e.g., 'MiCe'); Use [] to see list of available electrodes. sort_var = [string] Variable according to which the trials will be sorted (e.g., 'logitmnum'); Use [] to see list of available sorting variables. Note that sort_var can be over-ridden by optional 'valsort', 'phase_sort', or 'amp_sort' arguments (below). Optional Inputs I (Specifying Data & Function Verbosity) 'bins' = [integer vector] Bins to extract trials from. [] means to use all bins {default: use all bins} 'in_fname' = [string] File from compile_erpimageMK.m in which data are stored. Include the file's path unless the file is the current working directory. {default: use global variables} 'verblevel' = an integer specifiying the amount of information you want functions to provide about what they are 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 if not already globally specified} 3 - stuff that might help you debug (show all reports) Optional Inputs II (Data Preprocessing) 'replace_ties' = ['yes'|'no'] Replace trials with the same value of sort_var with the mean of those trials. Only works if sorting trials by sort_var. {default: 'yes'} 'avewidth' = [scalar>=0]. The standard deviation (in units of epochs) of the Gaussian window used to smooth (vertically) with a moving-average. Gaussian window extends three standard deviations below and three standard deviations above window center (trials beyond window are not incorporated into average). {default: 0, no smoothing} 'decimate' = Factor to decimate/interpolate ntrials by (may be non-integer) Else, if this is large (> sqrt(number of trials)), output this many epochs. {default: 0 <-same as erpimage.m} 'rmerp' = ['on'|'off'] Subtract the average ERP from each trial before processing {default: 'off'} 'evenodd' = ['on'|'off'] Split the data in two by separating even and odd trials (after sorting the data via sort_var). This will create two ERPimages. The optional arguments will be applied to each figure independently (e.g., if marktrials=10, then the 10th trial on both figures will be marked) {default: 'off'} Optional Inputs III (Plot Labels & Limits) 'title' = [string] Plot title {default: Channel name and bin descriptor (if only one bin) or list of bins} 'limits' = [lotime hitime minerp maxerp lodB hidB locoher hicoher basedB] Plot axes limits. Can use NaN (or nan, but not Nan) for missing items and omit late items. Use last input, basedB, to set the baseline dB amplitude in 'plotamps' plots {default: [NaN NaN]} 'sortvar_limits' = [min max] minimum and maximum sorting variable values to image. This only affects visualization of ERPimage and ERPs (not smoothing). Cannot be used if sorting by any factor besides sortvar (e.g., phase). 'signif' = [lo_dB, hi_dB, coher_signif_level] Use precomputed significance thresholds (as from outputs ampsig, cohsig) to save time. {default: ignore} 'cbar' = ['on'|'off'] Plot color bar to right of ERPimage {default: 'on'} 'caxis' = [lo hi] Set color axis limits. Else [fraction] Set caxis limits at (+/-)fraction*max(abs(data)) {default: +/- abs(data max)} 'noxlabel' = ['on'|'off'] Do not plot "Time (ms)" on the bottom x-axis {default: 'off'} Optional Inputs IV (Plotting Sorting Variable) 'renorm' = ['on'|'off'| formula] Normalize sorting variable to epoch latency range. 'on'= autoscale. formula must be a linear transformation in the format 'a*x+b' (e.g., '3*x+2'). {default: 'off'} 'plot_sort_var' = ['on'|'off'] Plot sort_var {default: 'on'} 'sortvarpercent' = [float vector] Plot percentiles for the sorting variable for instance, [0.1 0.5 0.9] plots the 10th percentile, the median and the 90th percentile. {default: ignored} Optional Inputs V (Adding ERP subplot) 'erp' = ['on'|'off'] Plot ERP time average of the trials below the image {default: 'on'} 'erpstd' = ['on'|'off'] Plot ERP +/- stdev. Requires 'erp' {default: 'off'} 'yerplabel' = [string] ERP ordinate axis label. Print uV with '\muV'. {default: 'ERP (\muV)'} Optional Inputs VI (Aligning Trials) 'align' = [latency] Time-lock data to sort_var. Plot sort_var at given latency (in ms). Else Inf -> plot sort_var at median sort_var latency {default: ignored} 'timewarp' = {[events], [warpms], {colors}} Time warp ERP, amplitude and phase time-courses before smoothing. 'events' is a matrix whose columns specify the latencies (in ms) at which a series of successive events occur in each trial. 'warpms' is an optional vector of latencies (in ms) to which the series of events should be time locked. (Note: Epoch start and end should not be declared as events or warpms}. If 'warpms' is absent or [], the median of each 'events' column will be used. {colors} contains a list of Matlab linestyles to use for vertical lines marking the occurrence of the time warped events. If '', no line will be drawn for this event column. If fewer colors than event columns, cycles through the given color labels. Note: Not compatible with 'vert' (below). {default: ignored} Optional Inputs VII (Trial Sorting) [Note: these options are mutually exclusive and override sort_var] 'valsort' = [startms endms direction] Sort data on (mean) value between startms and (optional) endms. Direction is 1 or -1. If -1, plot max-value epoch at bottom {default: sort on sort_var} 'phasesort' = [ms_center prct freq maxfreq topphase] Sort epochs by phase in a 3-cycle window centered at latency ms_center (ms). Percentile (prct) in range [0,100] gives percent of trials to reject for (too) low amplitude. Else, if in range [-100,0], percent of trials to reject for (too) high amplitude; freq (Hz) is the phase-sorting frequency. With optional maxfreq, sort by phase at freq of max power in the data in the range [freq,maxfreq] (Note: 'phasesort' arg freq overrides the frequency specified in 'coher'). With optional topphase, sort by phase, putting topphase (degrees, in range [-180,180]) at the top of the image. Note: 'phasesort' now uses circular smoothing. Use 'cycles' (below) for wavelet length. {default: sort on sort_var} 'ampsort' = [center_ms prcnt freq maxfreq] Sort epochs by amplitude. (See 'phasesort' above). If ms_center is 'Inf', then sorting is by mean power across the time window specified by 'sortwin' below. If third arg, freq, is < 0, sort by mean power in the range [ abs(freq) maxfreq ]. {default: sort on sort_var} 'sortwin' = [start_ms end_ms] If center_ms == Inf in 'ampsort' arg (above), sorts by mean amplitude across window centers shifted from start_ms to end_ms by 10 ms. {default: ignored} 'showwin' = ['on'|'off'] Show amp sorting window behind ERP trace. {default: 'off'} Optional Inputs VIII (Time/Frequency Information) 'coher' = [freq] Plot ERP average plus mean amplitude & coherence at freq (Hz) Else [minfrq maxfrq] = same, but select frequency with max power in given range. (Note: the 'phasesort' freq (above) overwrites these parameters). Else [minfrq maxfrq alpha] = plot coher. signif. level line at probability alpha (range: [0,0.1]) {default: no coher, no alpha level} 'cycles' = [float] Number of cycles in the wavelet time/frequency decomposition {default: 3} 'plotamps' = ['on'|'off'] Image amplitudes at each trial and latency instead of potential values. Note: Currently requires 'coher' (above) with alpha signif. Use 'cycles' (below) > (default) 3 for better frequency specificity, {default: plot potential, not amplitudes} Optional Inputs IX (Misc. Additional Plot Items) 'fig_id' = [integer(s)] ID number of Matlab figure window(s) in which to create the ERPimage. If ID is not specified, the erpimage will be generated in a new figure window. If generating two figures with 'evenodd' argument, 'fig_id' can be a vector of two integers. {default: []} 'topo' = ['on' | 'off'] Add a cartoon head indicating electrode position. Electrode information is stored with data. {default: 'on'} 'spec' = [loHz,hiHz] Plot the mean data spectrum at upper right of image. {default: not plot} 'mark_trials' = [vector of trials] Plot horizontal lines at specified epoch numbers. erpimage.m's "horz" option. {default: ignored} 'mark_times' = [vector of times] Plot vertical dashed lines at specified latencies (in ms). erpimage.m's "vert" option. {default: ignored} 'auxvar' = [size(nvars,ntrials) matrix] Plot auxiliary variable(s) for each trial as separate traces. Else, 'auxvar',{[matrix],{colorstrings}} to specify N trace colors. Ex: colorstrings = {'r','bo-','','k:'} (See also: 'vert' and 'timewarp' above). {default: ignored} 'r_plot' = ['on' | 'off'] Create an interactive figure that visualizes the linear correlation between EEG and sorting variable across all loaded time points and channels. {default: 'off'} 'r_fig_id' = [integer] ID number of Matlab figure window in which to create correlation plot (see option 'r_plot'). If ID is not specified, the correlation plot will be generated in a new figure window. {default: []} 'erp_grid' = ['on' | 'off'] If 'erp_grid' is added as an option voltage axis dashed grid lines will be added to the ERP plot to facilitate judging ERP amplitude 'img_trialax_label' = [string] The label of the axis corresponding to trials in the ERPimage (e.g., 'Reaction Time'). Note, if img_trialax_label is set to something besides 'Trials' or [], the tick marks on this axis will be set in units of the sorting variable. This is a useful alternative to plotting the sorting variable when the sorting variable is not in milliseconds. {default: 'Trials'} 'img_trialax_ticks' = Vector of sorting variable values at which tick marks (e.g., [300 350 400 450] for reaction time in msec) will appear on the trial axis of the erpimage. Tick mark values should be given in units img_trialax_label (e.g., 'Trials' or msec). {default: automatic} 'baseline' = [low_boundary high_boundary] a time window (in msec) whose mean amplitude in each trial will be removed from each trial (e.g., [-100 0]) after filtering. Useful in conjunction with 'filt' option to re-basline trials after they have been filtered. Not necessary if data have already been baselined and erpimage processing does not affect baseline amplitude {default: no further baselining of data} 'filt' = [low_boundary high_boundary] a two element vector indicating the frequency cut-offs for a 3rd order Butterworth filter that will be applied to each trial of data. If low_boundary=0, the filter is a high pass filter. If high_boundary=srate/2, then the filter is a low pass filter. If both boundaries are between 0 and srate/2, then the filter is a bandpass filter. If both boundaries are between 0 and -srate/2, then the filter is a bandstop filter (with boundaries equal to the absolute values of low_boundary and high_boundary). Note, using this option requires the 'srate' option to be specified and the signal processing toolbox function butter.m. You should probably use the 'baseline' option as well since the mean prestimulus baseline may no longer be 0 after the filter is applied {default: no filtering}
0001 function plot_erpimageMK(chan,sort_var,varargin) 0002 % plot_erpimageMK() - Produces an ERPimage from variables generated by 0003 % compile_erpimageMK.m using EEGLAB function erpimage.m 0004 % 0005 % Usage: 0006 % >> plot_erpimageMK(chan,sort_var,varargin) 0007 % 0008 % Required Inputs: 0009 % chan = [string] Name of electrode to plot (e.g., 'MiCe'); Use [] to see 0010 % list of available electrodes. 0011 % sort_var = [string] Variable according to which the trials will be sorted (e.g., 0012 % 'logitmnum'); Use [] to see list of available sorting variables. 0013 % Note that sort_var can be over-ridden by optional 'valsort', 0014 % 'phase_sort', or 'amp_sort' arguments (below). 0015 % 0016 % 0017 % Optional Inputs I (Specifying Data & Function Verbosity) 0018 % 'bins' = [integer vector] Bins to extract trials from. [] means to 0019 % use all bins {default: use all bins} 0020 % 'in_fname' = [string] File from compile_erpimageMK.m in which data are 0021 % stored. Include the file's path unless the file is the 0022 % current working directory. {default: use global 0023 % variables} 0024 % 'verblevel' = an integer specifiying the amount of information you want 0025 % functions to provide about what they are doing during runtime. 0026 % Options are: 0027 % 0 - quiet, only show errors, warnings, and EEGLAB reports 0028 % 1 - stuff anyone should probably know 0029 % 2 - stuff you should know the first time you start working 0030 % with a data set {default value if not already globally 0031 % specified} 0032 % 3 - stuff that might help you debug (show all reports) 0033 % 0034 % 0035 % Optional Inputs II (Data Preprocessing) 0036 % 'replace_ties' = ['yes'|'no'] Replace trials with the same value of 0037 % sort_var with the mean of those trials. Only works if sorting 0038 % trials by sort_var. {default: 'yes'} 0039 % 'avewidth' = [scalar>=0]. The standard deviation (in units of epochs) of the Gaussian 0040 % window used to smooth (vertically) with a moving-average. Gaussian 0041 % window extends three standard deviations below and three standard 0042 % deviations above window center (trials beyond window are not incorporated 0043 % into average). {default: 0, no smoothing} 0044 % 'decimate' = Factor to decimate/interpolate ntrials by (may be non-integer) 0045 % Else, if this is large (> sqrt(number of trials)), output this 0046 % many epochs. {default: 0 <-same as erpimage.m} 0047 % 'rmerp' = ['on'|'off'] Subtract the average ERP from each trial before 0048 % processing {default: 'off'} 0049 % 'evenodd' = ['on'|'off'] Split the data in two by separating even and 0050 % odd trials (after sorting the data via sort_var). This 0051 % will create two ERPimages. The optional arguments will 0052 % be applied to each figure independently (e.g., if 0053 % marktrials=10, then the 10th trial on both figures will 0054 % be marked) {default: 'off'} 0055 % 0056 % 0057 % Optional Inputs III (Plot Labels & Limits) 0058 % 'title' = [string] Plot title {default: Channel name and bin descriptor 0059 % (if only one bin) or list of bins} 0060 % 'limits' = [lotime hitime minerp maxerp lodB hidB locoher hicoher basedB] 0061 % Plot axes limits. Can use NaN (or nan, but not Nan) for missing items 0062 % and omit late items. Use last input, basedB, to set the 0063 % baseline dB amplitude in 'plotamps' plots {default: [NaN NaN]} 0064 % 'sortvar_limits' = [min max] minimum and maximum sorting variable 0065 % values to image. This only affects visualization of 0066 % ERPimage and ERPs (not smoothing). Cannot be used 0067 % if sorting by any factor besides sortvar (e.g., 0068 % phase). 0069 % 'signif' = [lo_dB, hi_dB, coher_signif_level] Use precomputed significance 0070 % thresholds (as from outputs ampsig, cohsig) to save time. 0071 % {default: ignore} 0072 % 'cbar' = ['on'|'off'] Plot color bar to right of ERPimage {default: 'on'} 0073 % 'caxis' = [lo hi] Set color axis limits. Else [fraction] Set caxis limits at 0074 % (+/-)fraction*max(abs(data)) {default: +/- abs(data max)} 0075 % 'noxlabel' = ['on'|'off'] Do not plot "Time (ms)" on the bottom x-axis 0076 % {default: 'off'} 0077 % 0078 % 0079 % Optional Inputs IV (Plotting Sorting Variable) 0080 % 'renorm' = ['on'|'off'| formula] Normalize sorting variable to epoch 0081 % latency range. 'on'= autoscale. formula must be a linear 0082 % transformation in the format 'a*x+b' (e.g., '3*x+2'). 0083 % {default: 'off'} 0084 % 'plot_sort_var' = ['on'|'off'] Plot sort_var {default: 'on'} 0085 % 'sortvarpercent' = [float vector] Plot percentiles for the sorting variable 0086 % for instance, [0.1 0.5 0.9] plots the 10th percentile, the median 0087 % and the 90th percentile. {default: ignored} 0088 % 0089 % Optional Inputs V (Adding ERP subplot) 0090 % 'erp' = ['on'|'off'] Plot ERP time average of the trials below the image 0091 % {default: 'on'} 0092 % 'erpstd' = ['on'|'off'] Plot ERP +/- stdev. Requires 'erp' {default: 'off'} 0093 % 'yerplabel' = [string] ERP ordinate axis label. Print uV with '\muV'. 0094 % {default: 'ERP (\muV)'} 0095 % 0096 % 0097 % Optional Inputs VI (Aligning Trials) 0098 % 'align' = [latency] Time-lock data to sort_var. Plot sort_var at given latency 0099 % (in ms). Else Inf -> plot sort_var at median sort_var latency 0100 % {default: ignored} 0101 % 'timewarp' = {[events], [warpms], {colors}} Time warp ERP, amplitude and phase 0102 % time-courses before smoothing. 'events' is a matrix whose columns 0103 % specify the latencies (in ms) at which a series of successive events occur 0104 % in each trial. 'warpms' is an optional vector of latencies (in ms) to which 0105 % the series of events should be time locked. (Note: Epoch start and end 0106 % should not be declared as events or warpms}. If 'warpms' is absent or [], 0107 % the median of each 'events' column will be used. {colors} contains a 0108 % list of Matlab linestyles to use for vertical lines marking the occurrence 0109 % of the time warped events. If '', no line will be drawn for this event 0110 % column. If fewer colors than event columns, cycles through the given color 0111 % labels. Note: Not compatible with 'vert' (below). 0112 % {default: ignored} 0113 % 0114 % 0115 % Optional Inputs VII (Trial Sorting) 0116 % [Note: these options are mutually exclusive and override sort_var] 0117 % 'valsort' = [startms endms direction] Sort data on (mean) value 0118 % between startms and (optional) endms. Direction is 1 or -1. 0119 % If -1, plot max-value epoch at bottom {default: sort on sort_var} 0120 % 'phasesort' = [ms_center prct freq maxfreq topphase] Sort epochs by phase in 0121 % a 3-cycle window centered at latency ms_center (ms). 0122 % Percentile (prct) in range [0,100] gives percent of trials 0123 % to reject for (too) low amplitude. Else, if in range [-100,0], 0124 % percent of trials to reject for (too) high amplitude; 0125 % freq (Hz) is the phase-sorting frequency. With optional 0126 % maxfreq, sort by phase at freq of max power in the data in 0127 % the range [freq,maxfreq] (Note: 'phasesort' arg freq overrides 0128 % the frequency specified in 'coher'). With optional topphase, 0129 % sort by phase, putting topphase (degrees, in range [-180,180]) 0130 % at the top of the image. Note: 'phasesort' now uses circular 0131 % smoothing. Use 'cycles' (below) for wavelet length. 0132 % {default: sort on sort_var} 0133 % 'ampsort' = [center_ms prcnt freq maxfreq] Sort epochs by amplitude. 0134 % (See 'phasesort' above). If ms_center is 'Inf', then sorting 0135 % is by mean power across the time window specified by 'sortwin' 0136 % below. If third arg, freq, is < 0, sort by mean power in the range 0137 % [ abs(freq) maxfreq ]. {default: sort on sort_var} 0138 % 'sortwin' = [start_ms end_ms] If center_ms == Inf in 'ampsort' arg (above), sorts 0139 % by mean amplitude across window centers shifted from start_ms 0140 % to end_ms by 10 ms. {default: ignored} 0141 % 'showwin' = ['on'|'off'] Show amp sorting window behind ERP trace. {default: 'off'} 0142 % 0143 % 0144 % Optional Inputs VIII (Time/Frequency Information) 0145 % 'coher' = [freq] Plot ERP average plus mean amplitude & coherence at freq (Hz) 0146 % Else [minfrq maxfrq] = same, but select frequency with max power in 0147 % given range. (Note: the 'phasesort' freq (above) overwrites these 0148 % parameters). Else [minfrq maxfrq alpha] = plot coher. signif. level line 0149 % at probability alpha (range: [0,0.1]) {default: no coher, no alpha level} 0150 % 'cycles' = [float] Number of cycles in the wavelet time/frequency decomposition {default: 3} 0151 % 'plotamps' = ['on'|'off'] Image amplitudes at each trial and latency instead of potential 0152 % values. Note: Currently requires 'coher' (above) with alpha signif. 0153 % Use 'cycles' (below) > (default) 3 for better frequency specificity, 0154 % {default: plot potential, not amplitudes} 0155 % 0156 % 0157 % Optional Inputs IX (Misc. Additional Plot Items) 0158 % 'fig_id' = [integer(s)] ID number of Matlab figure window(s) in which to create 0159 % the ERPimage. If ID is not specified, the erpimage will be generated 0160 % in a new figure window. If generating two figures 0161 % with 'evenodd' argument, 'fig_id' can be a vector of 0162 % two integers. {default: []} 0163 % 'topo' = ['on' | 'off'] Add a cartoon head indicating electrode 0164 % position. Electrode information is stored with data. 0165 % {default: 'on'} 0166 % 'spec' = [loHz,hiHz] Plot the mean data spectrum at upper right of image. 0167 % {default: not plot} 0168 % 'mark_trials' = [vector of trials] Plot horizontal lines at specified epoch numbers. 0169 % erpimage.m's "horz" option. {default: ignored} 0170 % 'mark_times' = [vector of times] Plot vertical dashed lines at specified latencies (in ms). 0171 % erpimage.m's "vert" option. {default: ignored} 0172 % 'auxvar' = [size(nvars,ntrials) matrix] Plot auxiliary variable(s) for each trial 0173 % as separate traces. Else, 'auxvar',{[matrix],{colorstrings}} 0174 % to specify N trace colors. Ex: colorstrings = {'r','bo-','','k:'} 0175 % (See also: 'vert' and 'timewarp' above). {default: ignored} 0176 % 'r_plot' = ['on' | 'off'] Create an interactive figure that visualizes the 0177 % linear correlation between EEG and sorting variable across all loaded 0178 % time points and channels. {default: 'off'} 0179 % 'r_fig_id' = [integer] ID number of Matlab figure window in which to create 0180 % correlation plot (see option 'r_plot'). If ID is not specified, the 0181 % correlation plot will be generated in a new figure window. {default: []} 0182 % 'erp_grid' = ['on' | 'off'] If 'erp_grid' is added as an option voltage axis dashed grid lines will be 0183 % added to the ERP plot to facilitate judging ERP amplitude 0184 % 'img_trialax_label' = [string] The label of the axis corresponding to trials in the ERPimage 0185 % (e.g., 'Reaction Time'). Note, if img_trialax_label is set to something 0186 % besides 'Trials' or [], the tick marks on this axis will be set in units 0187 % of the sorting variable. This is a useful alternative to plotting the 0188 % sorting variable when the sorting variable is not in milliseconds. {default: 'Trials'} 0189 % 'img_trialax_ticks' = Vector of sorting variable values at which tick marks (e.g., [300 350 400 450] 0190 % for reaction time in msec) will appear on the trial axis of the erpimage. Tick mark 0191 % values should be given in units img_trialax_label (e.g., 'Trials' or msec). 0192 % {default: automatic} 0193 % 'baseline' = [low_boundary high_boundary] a time window (in msec) whose mean amplitude in 0194 % each trial will be removed from each trial (e.g., [-100 0]) after filtering. 0195 % Useful in conjunction with 'filt' option to re-basline trials after they have been 0196 % filtered. Not necessary if data have already been baselined and erpimage 0197 % processing does not affect baseline amplitude {default: no further baselining 0198 % of data} 0199 % 'filt' = [low_boundary high_boundary] a two element vector indicating the frequency 0200 % cut-offs for a 3rd order Butterworth filter that will be applied to each 0201 % trial of data. If low_boundary=0, the filter is a high pass filter. If 0202 % high_boundary=srate/2, then the filter is a low pass filter. If both 0203 % boundaries are between 0 and srate/2, then the filter is a bandpass filter. 0204 % If both boundaries are between 0 and -srate/2, then the filter is a bandstop 0205 % filter (with boundaries equal to the absolute values of low_boundary and 0206 % high_boundary). Note, using this option requires the 'srate' option to be 0207 % specified and the signal processing toolbox function butter.m. You should 0208 % probably use the 'baseline' option as well since the mean prestimulus baseline 0209 % may no longer be 0 after the filter is applied 0210 % {default: no filtering} 0211 0212 % 0213 % 0214 % Outputs: 0215 % If data are not already in memory, the function sets some global 0216 % variables (see below). 0217 % 0218 % 0219 % Global Variables: 0220 % VERBLEVEL = level of verbosity (i.e., tells functions how much 0221 % how much to report about what they're doing during 0222 % runtime) set by the optional function argument 'verblevel' 0223 % in_fname = .eim file from which data were loaded (produced by 0224 % compile_erpimageMK.m) 0225 % chans = cell array specifiying the names of the channels loaded 0226 % into memory 0227 % chan_data = the EEG at all of the channels loaded into memory 0228 % chanlocs = EEG.chanlocs struct specifying channel locations 0229 % ep_info = information about each trial/epoch of data (in format of 0230 % EEG.event struct) 0231 % ep_times = start and stop time of each epoch (in ms) 0232 % bindesc = struct array of bin descriptors 0233 % srate = sampling rate 0234 % eim_bins = bins that were expicitly loaded when .eim file was created 0235 % rtmsec = reaction time info for each epoch (may be empty) 0236 % rtbins = specifies which reaction time value in rtmsec goes with 0237 % which bin (i.e., enables the same epoch to have different 0238 % RTs depending on which bin it is assigned to). 0239 % 0240 % Example: 0241 % >> setfile_tplate='/homes/dgroppe/SANDBOX/RTERPM/rtm#y.set'; 0242 % >> chans={'MiPf','MiCe','MiOc','LLOc','RLOc'}; 0243 % >> compile_erpimageMK(1:4,'setfile_tplate',setfile_tplate,'chans',chans, ... 0244 % 'bins',[127 133 142 157],'out_fname','demo.eim'); 0245 % >> plot_erpimageMK('MiCe','rtmsec','in_fname','demo.eim','avewidth',4,'fig_id',1); 0246 % 0247 % 0248 % Notes: 0249 % -You need to use the Kutaslab copy of erpimage.m for full functionality. 0250 % The current EEGLAB version of erpimage.m doesn't quite have all the 0251 % options of the Kutaslab version. 0252 % 0253 % -Almost all function arguments are simply erpimage.m function arguments. 0254 % See the erpimage.m documentation (e.g., type "help erpimage" at the 0255 % Matlab command line) for more information about what how to use them and 0256 % for examples. 0257 % 0258 % -erpimage.m only accepts a limited number of total arguments. You might 0259 % exceed this number with this function. If that happens you'll need to 0260 % reduce the number of optional inputs or change erpimage.m 0261 % 0262 % -The following erpimage.m options are not implemented here because I 0263 % don't feel they're useful: erpalpha (doesn't correct for multiple 0264 % comparisons), noshow, & nosort. 0265 % 0266 % -Decimate needs to be relatively high relative to the number of trials to 0267 % produce a noticeable difference. 0268 % 0269 % -To make a zoomable ERPimage so that you can better see what's going on 0270 % for subsets of the sorting variable or brief time windows. Set 'erps' to 0, 0271 % and then click on the ERPimage. A new figure should appear with just the 0272 % ERPimage which should be zoomable. 0273 % 0274 % -The number of trials that are reported in the automatically generated 0275 % figure title are the number of trials before decimation. 0276 % 0277 % Author: 0278 % David Groppe 0279 % Kutaslab, 8/2009 0280 % 0281 0282 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%% 0283 % 0284 0285 %%%%%%%%%%%%%%%% POSSIBLE FUTURE DEVELOPMENT %%%%%%%%%%%%%%%% 0286 %-If topos are not plot (i.e., 'topos' is 'off'), figure background is grey. Otherwise, 0287 %figure background is EEGLAB blue. It would be nice to have it be 0288 %consistent. 0289 % 0290 %-When aligning to sorting variable, the original epoch time limits are 0291 %used. Thus, you see very little before the sorting variable. This needs 0292 %to be fixed in erpimage.m. 0293 0294 global in_fname; 0295 global chan_data; 0296 global chans; 0297 global chanlocs; 0298 global ep_info; 0299 global ep_times; 0300 global bindesc; 0301 global srate; 0302 global rtmsec; 0303 global rtbins; 0304 global VERBLEVEL 0305 global eim_bins 0306 0307 %Input Parser 0308 p=inputParser; 0309 %Note: the order of the required arguments needs to match precisely their 0310 %order in the function definition (which is also the order used by p.parse 0311 %below) 0312 p.addRequired('chan',@(x) ischar(x) || isempty(x)); 0313 p.addRequired('sort_var',@(x) ischar(x) || isempty(x)); 0314 p.addParamValue('bins',[],@isnumeric); %default is to use all bins 0315 p.addParamValue('in_fname',[],@ischar); %default is to use global variables 0316 p.addParamValue('fig_id',[],@(x) sum(x>=0) || isempty(x)); 0317 p.addParamValue('avewidth',0,@isnumeric); 0318 p.addParamValue('replace_ties','on',@ischar); 0319 p.addParamValue('verblevel',[],@(x) x>=0); 0320 p.addParamValue('title',[],@(x) ischar(x) || isempty(x));%default is to use chan name & bin descriptor 0321 p.addParamValue('erp','on',@(x) ischar(x) || ((x>=1) & (x<=4))); 0322 p.addParamValue('erpstdev','off',@ischar); 0323 p.addParamValue('rmerp','off',@ischar); 0324 p.addParamValue('topo','on',@ischar); 0325 p.addParamValue('plot_sort_var','on',@ischar); 0326 p.addParamValue('showwin','off',@ischar); 0327 p.addParamValue('renorm','off',@ischar); 0328 p.addParamValue('limits',[NaN NaN],@isnumeric); 0329 p.addParamValue('sortvar_limits',[],@isnumeric); 0330 p.addParamValue('decimate',0,@isnumeric); 0331 p.addParamValue('mark_times',[],@isnumeric); 0332 p.addParamValue('mark_trials',[],@isnumeric); 0333 p.addParamValue('sortvarpercent',[],@(x) min(x>=0) & min(x<=1)); 0334 p.addParamValue('align',[],@isnumeric); 0335 p.addParamValue('coher',[],@(x) min(x>=0)); 0336 p.addParamValue('cycles',3,@(x) (x>0)); 0337 p.addParamValue('plotamps','off',@ischar); 0338 p.addParamValue('spec',[],@(x) min(x>=0)); 0339 p.addParamValue('cbar','on',@ischar); 0340 p.addParamValue('caxis',[],@(x) isnumeric(x) || isempty(x)); 0341 p.addParamValue('auxvar',[],@(x) isnumeric(x) || iscell(x)); 0342 p.addParamValue('noxlabel','off',@ischar); 0343 p.addParamValue('yerplabel','ERP(\muV)',@ischar); 0344 p.addParamValue('timewarp',[],@iscell); 0345 p.addParamValue('r_plot','off',@(x) strcmpi(x,'on') || strcmpi(x,'off')); 0346 p.addParamValue('r_fig_id',[],@isnumeric); 0347 %Sorting options 0348 p.addParamValue('phasesort',[],@isnumeric); 0349 p.addParamValue('signif',[],@isnumeric); 0350 p.addParamValue('ampsort',[],@isnumeric); 0351 p.addParamValue('sortwin',[],@isnumeric); 0352 p.addParamValue('valsort',[],@isnumeric); 0353 p.addParamValue('evenodd','off',@ischar); 0354 p.addParamValue('erp_grid','on',@ischar); 0355 p.addParamValue('img_trialax_label','Trials',@ischar); 0356 p.addParamValue('img_trialax_ticks',[],@isnumeric); 0357 p.addParamValue('filt',[],@isnumeric); 0358 p.addParamValue('baseline',[],@isnumeric); 0359 0360 p.parse(chan,sort_var,varargin{:}); 0361 0362 if isempty(VERBLEVEL) && isempty(p.Results.verblevel) 0363 VERBLEVEL=2; 0364 elseif ~isempty(p.Results.verblevel) 0365 VERBLEVEL=p.Results.verblevel; 0366 end 0367 0368 %?? put in error for arguments that should be integers when they are not 0369 %integers? 0370 0371 if isempty(p.Results.in_fname) 0372 %if input file wasn't specified, assume that data are in global 0373 %variables 0374 if isempty(chan_data) || isempty(chans) || isempty(chanlocs) || isempty(ep_info) ... 0375 || isempty(ep_times) || isempty(bindesc) || isempty(srate), 0376 error(sprintf(['You either need to specify an input filename (argument "in_fname") ' ... 0377 'or you need to appropriately fill the following global variables: ' ... 0378 'chan_data, chans, chanlocs, ep_info, ep_times, bindesc, & srate.\n' ... 0379 'The function compile_erpimageMK.m can do this for you.\n'])); 0380 end 0381 in_fname=[]; %indicates that data were already global 0382 elseif strcmp(in_fname,p.Results.in_fname) 0383 %if input file matches file from which data in global variables were 0384 %taken from, use the data in global variables to save the time it takes 0385 %to reload the data from the file 0386 if isempty(chan_data) || isempty(chans) || isempty(chanlocs) || isempty(ep_info), 0387 %some critical variables are not already in global memory, try to 0388 %load everything from file afterall 0389 load(p.Results.in_fname,'-MAT'); 0390 else 0391 fprintf('in_filename %s matches source of data already in memory.\n',p.Results.in_fname); 0392 fprintf('Will use data already in memory to save time.\n'); 0393 fprintf('If you would rather load the data from the file enter the\n'); 0394 fprintf(' following at the Matlab command line: '); 0395 fprintf('>> clear global in_fname\n'); 0396 end 0397 else 0398 load(p.Results.in_fname,'-MAT'); 0399 in_fname=p.Results.in_fname; 0400 msg=sprintf('Loading file %s into global variables.\n',in_fname); 0401 msg=[msg sprintf('One of these variables, chan_data, may be quite large.\n')]; 0402 msg=[msg sprintf('To delete it, enter >> clear global chan_data\n')]; 0403 VerbReport(msg,2,VERBLEVEL); 0404 end 0405 0406 0407 %Check to make sure we have the desired channel 0408 got_it=0; 0409 for a=1:length(chans), 0410 if strcmpi(chans{a},chan), 0411 got_it=1; 0412 end 0413 end 0414 if ~got_it 0415 msg=sprintf('Channel %s is not an option.\nCurrently loaded channels are: ',chan); 0416 for a=1:(length(chans)-1), 0417 msg=[msg chans{a} ', ']; 0418 end 0419 msg=[msg chans{length(chans)}]; 0420 error(msg); 0421 end 0422 0423 0424 %Check to make sure we have the desired sorting variable 0425 got_srtvar=0; 0426 %RT is a special sorting variable, since there may be more than one RT per 0427 %trial 0428 sortby_rt=0; 0429 rt_loaded=0; 0430 if exist('rtmsec','var') 0431 if ~isempty(rtmsec), 0432 rt_loaded=1; 0433 if strcmpi(sort_var,'rtmsec'), 0434 sortby_rt=1; 0435 got_srtvar=1; 0436 end 0437 end 0438 end 0439 0440 %Check for non-RT sorting variables 0441 if ~sortby_rt, 0442 fldnms=fieldnames(ep_info); 0443 possible=[]; 0444 desired=['event' sort_var]; 0445 for a=1:length(fldnms), 0446 if strcmpi('event',fldnms{a}(1:5)) && ~strcmpi('eventrtmsec',fldnms{a}) && (length(fldnms{a})>5), 0447 %i.e., it is not "event", note rtmsec sorting variable should 0448 %have been caught above already 0449 cmnd=['isnumeric(ep_info(a).' fldnms{a} ')']; 0450 if (eval(cmnd)), 0451 if strcmpi(desired,fldnms{a}), 0452 got_srtvar=1; 0453 break; %break a loop 0454 else 0455 possible=[possible a]; 0456 end 0457 end 0458 end 0459 end 0460 end 0461 if ~got_srtvar, 0462 msg=sprintf('Sorting variable %s is not an option.\nCurrently loaded sorting variables are: ',sort_var); 0463 for a=1:(length(possible)-1), 0464 msg=[msg fldnms{possible(a)}(6:end) ', ']; 0465 end 0466 msg=[msg fldnms{possible(end)}(6:end)]; %last/penultimate possibility doesn't need comma 0467 if rt_loaded, 0468 msg=[msg ', rtmsec']; 0469 end 0470 error(msg); 0471 end 0472 0473 %Extract data from specified bins and sorting variable from epoch info 0474 n_ep=length(ep_info); 0475 srt_val=zeros(1,n_ep)*NaN; 0476 %file_id=zeros(1,n_ep); %??DG 0477 0478 %note, srt_val indicates which epochs are to be ignored with NaN values 0479 %erpimage.m automatically ignores epochs with NaN srt_var values 0480 for a=1:n_ep, 0481 %%%%%% use a subset of bins %%%%%% 0482 if ~isempty(p.Results.bins), 0483 got_it=0; 0484 if sortby_rt, 0485 %make sure the RTs are the same for all bins 0486 %preallocate memory 0487 rt_ids=zeros(1,length(p.Results.bins)); 0488 rt_ids_ct=0; 0489 for d=p.Results.bins, 0490 rt_id=find(rtbins{a}==d); 0491 if ~isempty(rt_id), 0492 rt_ids_ct=rt_ids_ct+1; 0493 rt_ids(rt_ids_ct)=rt_id; 0494 end 0495 %rt_ids=[rt_ids find(rtbins{a}==d)]; %find all the rts for all the desired bins 0496 end 0497 if rt_ids_ct>0, 0498 uni_rt=unique(rtmsec{a}(rt_ids(1:rt_ids_ct))); 0499 if length(uni_rt)>1, 0500 error(sprintf(['Different bins have different RTs for epoch %d.\n' ... 0501 'You must specify bins that have the same RTs.'],a)); 0502 else 0503 srt_val(a)=uni_rt; %get the RT 0504 got_it=1; 0505 end 0506 end 0507 else %non-RT sorting variable 0508 for b=p.Results.bins, 0509 for c=1:length(ep_info(a).eventtype), 0510 if strcmpi(ep_info(a).eventtype{c},['bin' int2str(b)]), %does this trial fall in a desired bin? 0511 %c=length(ep_info(a).eventtype); %break c loop 0512 %b=p.Results.bins(end); %break b loop 0513 cmnd=['srt_val(a)=ep_info(a).event' p.Results.sort_var ';']; 0514 eval(cmnd); 0515 got_it=1; 0516 break; %break c loop 0517 end 0518 end 0519 if got_it, 0520 break; %break b loop 0521 end 0522 end 0523 end 0524 if ~got_it, %epoch not a member of desired bin 0525 srt_val(a)=NaN; 0526 end 0527 0528 %%%%%% no bins specified, use all bins %%%%%% 0529 else 0530 if sortby_rt, 0531 uni_rt=unique(rtmsec{a}); 0532 if length(uni_rt)>1, 0533 error(sprintf(['Different bins have different RTs for epoch %d.\n' ... 0534 'You must specify bins that have the same RTs.'],a)); 0535 else 0536 srt_val(a)=uni_rt; 0537 end 0538 else 0539 cmnd=['srt_val(a)=ep_info(a).event' p.Results.sort_var ';']; 0540 eval(cmnd); 0541 end 0542 end 0543 end 0544 0545 0546 %Find index to desired electrode in chanlocs 0547 n_loc=length(chanlocs); 0548 clocs_id=[]; %in case channel isn't in chanlocs 0549 for d=1:n_loc, 0550 if strcmpi(chanlocs(d).labels,chan), 0551 clocs_id=d; 0552 break; %break d loop 0553 end 0554 end 0555 0556 0557 %Find index to desired electrode in chans (a cell array of channel names 0558 %currently loaded into memory) 0559 n_chans=length(chans); 0560 chans_id=[]; %in case channel isn't in chans 0561 for d=1:n_chans, 0562 if strcmpi(chans{d},chan), 0563 chans_id=d; 0564 break; %break d loop; 0565 end 0566 end 0567 0568 %Compile plot title 0569 if isempty(p.Results.title), 0570 fig_title=[chan ': ']; %Note, Matlab warning that fig_title might not be used is because Matlab can't figure out that it's used via eval.m 0571 if isempty(p.Results.bins), 0572 if length(eim_bins)==length(bindesc), 0573 fig_title=[fig_title ' All Bins']; 0574 else 0575 fig_title=[fig_title 'Bins ']; 0576 for a=1:(length(eim_bins)-1), %only a subset of bins stored in eim file 0577 fig_title=[fig_title int2str(eim_bins(a)) ', ']; 0578 end 0579 fig_title=[fig_title int2str(eim_bins(end))]; 0580 end 0581 elseif length(p.Results.bins)==1, 0582 %one bin, make title bin descriptor 0583 fig_title=[fig_title bindesc{p.Results.bins}]; 0584 else 0585 fig_title=[fig_title 'Bins ']; 0586 for a=1:(length(p.Results.bins)-1), 0587 fig_title=[fig_title int2str(p.Results.bins(a)) ', ']; 0588 end 0589 fig_title=[fig_title int2str(p.Results.bins(end))]; 0590 end 0591 else 0592 fig_title=p.Results.title; 0593 end 0594 0595 0596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0597 % Compute correlations between sort var and all loaded channels 0598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0599 if strcmpi('on',p.Results.r_plot), 0600 VerbReport(' ',2,VERBLEVEL); 0601 VerbReport('Computing and plotting linear correlation between single trials and sorting variable.',2,VERBLEVEL); 0602 0603 % VerbReport('Left click on plot of correlations across time to see correlation topography at that point in time.',2,VERBLEVEL); 0604 % VerbReport('Vertical solid black line indicates time point correspoding to currently shown topography.',2,VERBLEVEL); 0605 % VerbReport(' ',2,VERBLEVEL); 0606 % if isempty(p.Results.r_fig_id), 0607 % figure; 0608 % else 0609 % figure(p.Results.r_fig_id); clf; 0610 % end 0611 0612 if isempty(p.Results.bins), 0613 if length(eim_bins)==length(bindesc), 0614 cor_fig_title=' All Bins'; 0615 else 0616 cor_fig_title='Bins '; 0617 for a=1:(length(eim_bins)-1), %only a subset of bins stored in eim file 0618 cor_fig_title=[cor_fig_title int2str(eim_bins(a)) ', ']; 0619 end 0620 cor_fig_title=[cor_fig_title int2str(eim_bins(end))]; 0621 end 0622 elseif length(p.Results.bins)==1, 0623 %one bin, make title bin descriptor 0624 cor_fig_title=bindesc{p.Results.bins}; 0625 else 0626 cor_fig_title='Bins '; 0627 for a=1:(length(p.Results.bins)-1), 0628 cor_fig_title=[cor_fig_title int2str(p.Results.bins(a)) ', ']; 0629 end 0630 cor_fig_title=[cor_fig_title int2str(p.Results.bins(end))]; 0631 end 0632 plot_eimcorr(p.Results.sort_var,'in_fname',in_fname,'title',cor_fig_title, ... 0633 'bins',p.Results.bins,'fig_id',p.Results.r_fig_id); 0634 end 0635 0636 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot ERPimage %%%%%%%%%%%%%%%%%%%%%%%%%%%% 0637 % Note, that erpimage.m caps the number of acceptable arguments. Thus, I 0638 % had to create all these "if" statement to try to minimize the number of 0639 % arguments. Sorry for the ugly programming. 0640 0641 if strcmpi(p.Results.evenodd,'on'), 0642 %sort the usable trials and take every other trial 0643 [vals, ids]=sort(srt_val); %NaN values are last 0644 odd_ids=ids(1:2:end); 0645 even_ids=setdiff(1:length(ids),odd_ids); 0646 n_plots=2; 0647 else 0648 n_plots=1; 0649 end 0650 0651 %potentially loop through twice for odd and even trials 0652 for plotloop=1:n_plots, 0653 0654 if strcmpi(p.Results.evenodd,'on'), 0655 if plotloop==1, 0656 use_ids=odd_ids; 0657 if isempty(p.Results.sortvar_limits) 0658 n_trials=sum(~isnan(srt_val(use_ids))); 0659 else 0660 n_trials=sum( (srt_val(use_ids)>=p.Results.sortvar_limits(1)) && (srt_val(use_ids)<=p.Results.sortvar_limits(2))); 0661 end 0662 use_title=[fig_title ' (' int2str(n_trials) ' Odd Trials)']; 0663 else 0664 use_ids=even_ids; 0665 if isempty(p.Results.sortvar_limits) 0666 n_trials=sum(~isnan(srt_val(use_ids))); 0667 else 0668 n_trials=sum( (srt_val(use_ids)>=p.Results.sortvar_limits(1)) && (srt_val(use_ids)<=p.Results.sortvar_limits(2))); 0669 end 0670 use_title=[fig_title ' (' int2str(n_trials) ' Even Trials)']; 0671 end 0672 else 0673 use_ids=1:length(srt_val); 0674 use_title=fig_title; 0675 %add number of trials to title if title is auto generated 0676 if isempty(p.Results.title), 0677 if isempty(p.Results.sortvar_limits) 0678 n_trials=sum(~isnan(srt_val(use_ids))); 0679 else 0680 n_trials=sum( (srt_val(use_ids)>=p.Results.sortvar_limits(1)).*(srt_val(use_ids)<=p.Results.sortvar_limits(2))); 0681 end 0682 use_title=[use_title ' (' int2str(n_trials) ' trials)']; 0683 end 0684 end 0685 0686 0687 %Plot sorting variable 0688 if strcmpi(p.Results.plot_sort_var,'on') 0689 noplot='off'; %Note, Matlab warning that noplot might not be used is because Matlab can't figure out that it's used via eval.m 0690 else 0691 noplot='on'; 0692 end 0693 0694 %change "on/off" to "yes/no", erpimage uses both for different arguments and this function uses 0695 %just "on/off" for all arguments 0696 if strcmpi(p.Results.renorm,'on'), 0697 renorm='yes'; %Note, Matlab warning that renorm might not be used is because Matlab can't figure out that it's used via eval.m 0698 elseif strcmpi(p.Results.renorm,'off'), 0699 renorm='no'; 0700 else 0701 renorm=p.Results.renorm; %should be a formula 0702 end 0703 0704 cmd=['erpimage(chan_data{chans_id}(:,use_ids),srt_val(use_ids),ep_times,use_title,' ... 0705 'p.Results.avewidth,p.Results.decimate,' ... 0706 '"cbar",p.Results.cbar,' ... 0707 '"limits",p.Results.limits,' ... 0708 '"noplot",noplot,' ... 0709 '"erp",p.Results.erp,' ... 0710 '"img_trialax_label",p.Results.img_trialax_label,' ... 0711 '"img_trialax_ticks",p.Results.img_trialax_ticks,' ... 0712 '"filt",p.Results.filt,' ... 0713 '"baseline",p.Results.baseline,' ... 0714 '"replace_ties",p.Results.replace_ties,' ... 0715 '"yerplabel",p.Results.yerplabel,']; 0716 0717 0718 if strcmpi(p.Results.erp_grid,'on') 0719 cmd=[cmd '"erp_grid",']; 0720 end 0721 0722 if ~isempty(p.Results.sortvar_limits) 0723 cmd=[cmd '"sortvar_limits",p.Results.sortvar_limits,']; 0724 end 0725 0726 if ~isempty(p.Results.timewarp), 0727 cmd=[cmd '"timewarp",p.Results.timewarp,']; 0728 elseif ~isempty(p.Results.mark_times), 0729 cmd=[cmd '"vert",p.Results.mark_times,']; 0730 end 0731 0732 if strcmpi(p.Results.erpstdev,'on'), 0733 cmd=[cmd '"erpstd",p.Results.erpstdev,']; 0734 end 0735 0736 if strcmpi(p.Results.rmerp,'on'), 0737 cmd=[cmd '"rmerp",p.Results.rmerp,']; 0738 end 0739 0740 if strcmpi(p.Results.topo,'on'), 0741 cmd=[cmd '"topo",{clocs_id,chanlocs,[]},']; 0742 end 0743 0744 if ~isempty(p.Results.auxvar), 0745 cmd=[cmd '"auxvar",p.Results.auxvar,']; 0746 end 0747 0748 if ~isempty(p.Results.spec), 0749 cmd=[cmd '"spec",p.Results.spec,']; 0750 end 0751 0752 if ~isempty(p.Results.caxis), 0753 cmd=[cmd '"caxis",p.Results.caxis,']; 0754 end 0755 0756 if ~isempty(p.Results.mark_trials), 0757 cmd=[cmd '"horz",p.Results.mark_trials,']; 0758 end 0759 0760 if (p.Results.cycles~=3), 0761 cmd=[cmd '"cycles",p.Results.cycles,']; 0762 end 0763 0764 if ~isempty(p.Results.signif) 0765 cmd=[cmd '"signif",p.Results.signif,']; 0766 end 0767 0768 %if using some option involving the frequency domain 0769 if ~isempty(p.Results.spec) || ~isempty(p.Results.ampsort) || ~isempty(p.Results.phasesort) ... 0770 || ~isempty(p.Results.coher) 0771 cmd=[cmd '"srate",srate,']; 0772 end 0773 0774 if ~isempty(p.Results.coher), 0775 cmd=[cmd '"coher",p.Results.coher,' ... 0776 '"plotamps",p.Results.plotamps,']; 0777 end 0778 0779 %sorting criteria are mutually exclusive 0780 if ~isempty(p.Results.align) 0781 cmd=[cmd '"align",p.Results.align,']; 0782 VerbReport(sprintf('\nSorting by sort_var %s. Any other sorting criteria will be ignored.',sort_var),2,VERBLEVEL); 0783 VerbReport(sprintf('\n%d trials will be considered for ERPimage\n',sum(~isnan(srt_val))),1,VERBLEVEL); 0784 if sum(~isnan(srt_val))==0, 0785 errordlg('No trials have values for selected sorting variable.','plot_erpimageMK error','on'); 0786 return; 0787 end 0788 elseif ~isempty(p.Results.valsort) 0789 cmd=[cmd '"valsort",p.Results.valsort,']; 0790 VerbReport('Sorting by "valsort" any other sorting criteria will be ignored.',2,VERBLEVEL); 0791 elseif ~isempty(p.Results.phasesort) 0792 cmd=[cmd '"phasesort",p.Results.phasesort,']; 0793 VerbReport('Sorting by "phasesort" any other sorting criteria will be ignored.',2,VERBLEVEL); 0794 elseif ~isempty(p.Results.ampsort), 0795 VerbReport('Sorting by "ampsort" any other sorting criteria will be ignored.',2,VERBLEVEL); 0796 if ~isempty(p.Results.sortwin), 0797 cmd=[cmd '"showwin",p.Results.showwin,' ... 0798 '"sortwin",p.Results.sortwin,' ... 0799 '"ampsort",p.Results.ampsort,']; 0800 else 0801 cmd=[cmd '"ampsort",p.Results.ampsort,']; 0802 end 0803 else %sort according to srt_val 0804 VerbReport(sprintf('\nSorting by sort_var %s. Any other sorting criteria will be ignored.',sort_var),2,VERBLEVEL); 0805 VerbReport(sprintf('\n%d trials will be considered for ERPimage\n',sum(~isnan(srt_val))),1,VERBLEVEL); 0806 if sum(~isnan(srt_val))==0, 0807 errordlg('No trials have values for selected sorting variable.','plot_erpimageMK error','on'); 0808 return; 0809 end 0810 cmd=[cmd '"renorm",renorm,' ... 0811 '"sortvarpercent",p.Results.sortvarpercent,']; 0812 end 0813 0814 0815 %wrap up with general optional arguments 0816 cmd=[cmd '"noxlabel",p.Results.noxlabel,"avg_type","Gaussian","cbar_title","\muV");']; 0817 0818 %replace double quotes with single quotes 0819 dq_id=find(cmd=='"'); 0820 cmd(dq_id)=39; 0821 %display erpimage command if user wants max verbosity 0822 VerbReport('',3,VERBLEVEL); 0823 VerbReport('erpimage function call:',3,VERBLEVEL); 0824 VerbReport(cmd,3,VERBLEVEL); 0825 VerbReport('',3,VERBLEVEL); 0826 0827 %Open/Select Figure 0828 if length(p.Results.fig_id)<plotloop 0829 figure; 0830 elseif (p.Results.fig_id(plotloop)==0), 0831 figure; 0832 else 0833 figure(p.Results.fig_id(plotloop));clf; 0834 end 0835 0836 eval(cmd); 0837 set(gcf,'name',['[' use_title ']']); 0838 end