[Eeglablist] time frequency averaging

Joseph Brooks jlbrooks at socrates.berkeley.edu
Fri Jan 28 18:01:26 PST 2005


Brian,

Collapsing ERSP and ITC across subjects is easy. I have written a script 
(attached) to do this or you can write your own. For your own, write a 
simple script to run the timef function, collect the output matrices into 
variables and then take the mean across the subjects. The MEAN function in 
matlab can do this in one line of code. Collect the output ERSP maps into a 
3D matrix with the dimensions (subjects,time,frequency). You can then use

mean(matrix_name,1);

to average over the first dimension of the matrix to create a 2D matrix of 
dimensions (time, frequency).

You can do this all on your own or you can try out a script that I have 
written for multiple subjects analysis. This is one of several functions 
that I will be releasing to the list soon as a plugin to EEGLAB. I'm 
currently making sure that the GUI works on various platforms and finishing 
the GUI for the statistics part of the plugin.

This function ERSPAVG, brings up a window in which you select all of the 
input files (.set from EEGLAB or .mat from Brain Vision Analyzer). So, if 
you have 16 subjects, you select 16 files. You then specify a file for the 
output. The final dialog box collects parameters for the timef analysis and 
then passes the info to timef. The data for each subject are analyzed and 
stored in a matlab structure called ERSP and saved along with the summary 
statistics (mean, median, etc) across subjects.

This function works well for me but it may still have some bugs once people 
with different data sets start using it. Let me know if you have any 
problems and I'll try to address them. To use the function just put it in 
your matlab path and type ERSPAVG. You should have the latest version of 
EEGLAB installed.

I hope that you find it useful.

Joe



At 04:00 PM 1/28/2005, you wrote:
>I have used the channel time frequency plot option in EEG lab to get ERSP 
>and ITC.  It would be useful for me to be able to use this function across 
>groups of subjects.  I imagine that this is possible, but I am unsure how 
>to proceed.  I know that I could use the merge function to join datasets, 
>but I am looking at a dataset where only epochs with correct responses are 
>of interest, so merging would allow a subject who responded correctly more 
>to have a larger influence on the grand average - this is not what I 
>want.  Does anyone know how to do this?  An example EEG.history script 
>would be great.
>thanks,
>Brian
>
>_______________________________________________
>eeglablist mailing list eeglablist at sccn.ucsd.edu
>http://sccn.ucsd.edu/mailman/listinfo/eeglablist
>Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
>To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu
-------------- next part --------------
function erspavg

% erspavg() - Average Spectral Analysis Across Subjects - V 1.0beta
%
% USAGE:
%   >> erspavg;
%
% INPUTS:
%   all inputs selected by user interface windows
%
% OUTPUTS:
%   ERSP     - eeglab structure containing results of timef for individual
%   subjects as well as the averages across subjects
%
% DETAILED DESCRIPTION:
%
%   Computes the spectrograms for the selected data sets (subjects) and then
%   computes the various summary statistic spectrograms across the data sets
%   (subjects). All results are stored in a matlab structure and then saved
%   in the specified file. ITC and ERP results are also computed and their
%   summary statistics stored. 
% 
%   Inputs: The program takes data in the .mat format as exported 
%   from Brain Vision Analyzer as well as EEGlab .set files. If you are using 
%   another data format, you will need to convert it to one of these formats 
%   before using this function. Conversions to .set can be done easily for most 
%   formats using the various import functions available within EEGlab. Export 
%   from Brain Vision Analyzer can be done via the CreateMATfile Macro available 
%   from BrainProducts support.
%
%   Outputs: Output data is stored in a Matlab structure variable and
%   saved as a .mat file with the name specified. The matlab structure
%   variable is called 'ERSP' and contains 3 fields: 'subjects',
%   'info', and 'summarystats'. All of the output data is contained within
%   these fields and can be accessed by loading the variable into the matlab
%   workspace and typing 'ERSP' at the prompt. Subfields can be accessed with
%   the dot notation. See the Matlab help file for more on understanding
%   Matlab structure variables.
%
% MATLAB VERSION COMPATIBILITY: This function was written under Matlab
% 7.0.1 and EEGlab 4.512. It has also been tested under Matlab 6.5.1. OS 
% compatibility was tested under Windows XP SP2, Linux, and Mac OS X. Using 
% the most up-to-date version of EEGlab is highly recommended. The use of
% uiGetFilesJava to select multiple input files relies on having Java 1.3.1
% or later installed. If using windows and you have the uigetfiles function
% installed (downloadable from Matlab Central) then this will run instead
% of the Java function.
%
% LAST REVISION: January 3, 2005 by J.L.B.
%
% AUTHORS: Joseph L Brooks and James Marshel
%          Department of Psychology, University of California, Berkeley
%
% See also: 
%   CROSSFAVG, ERSPMAP, ERSPPLOT
%
% Copyright (C) <2004>  <Joseph Brooks and James Marshel>


% REVISION HISTORY
%
% 12.27.2004 - Changed electrode selection to a list dialog box. The list is
% automatically generated from the electrodes available in the selected
% files. This is done by loading just the channel variable from each file.
% I also started to add a warning message to indicate when selected
% electrodes aren't available in all files. 
%
% 12.28.2004 - Added a check of the sampling rate at the beginning of the
% program. This checks to make sure that the sampling rates for all of the
% selected files are the same. If they are not, it displays an error and
% ends the program. Also added a check of the time index arrays to ensure
% that they are the same across the files. Fixed cancel button on electrode
% selection dialog to end program when clicked.
%
% 01.03.2005 - Added a section to ask for the processing parameters related
% to whether FFT or wavelets are used to compute the ERSP. 
% 
% 01.03.2005 - Reformatted the output data structure...added ERP
% computations for individual subjects and summary statistics. Also added a
% record of the number of trials going into each subject's analysis and an
% average of this in the summary statistics. Added various other pieces of
% information to the output structure. The reformatting of the data
% structure reduced redundancy and added new information.
%
% 01.15.2005 - Added check to see if the current OS is windows and if the
% uigetfiles function is installed. If either of these are not true, the
% java version of uigetfiles is run instead. The java version code has been
% inserted at the end of the m-file.

% IDEAS FOR NEW FEATURES
%
% - Add option to save .set files of EEG for each subject



ERSP.info.version = '1.0 beta';
ERSP.info.history = date;

%%%% SELECT INPUT DATA FILES
junk = functions(@uigetfiles);

if ispc && ~isempty(junk.file)
    [filenames,pathname] = uigetfiles('*.mat; *.set','ERSPAVG - Select the data files to analyze');
else
    [files,pathname] = uiGetFilesJava;
    
    for i = 1:size(files,1)
        filenames{i} = files(i,:);
    end
end

if isempty(filenames)
    return;
end;

%%%% VERIFY FILETYPES ARE .SET or .MAT AND IF NOT DISPLAY ERROR MESSAGE

for i = 1:size(filenames,2)
    if ~strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.mat') && ~strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.set')
        errordlg('The selected files must be either .mat or .set files. At least one of your files does not meet this criterion. Convert the files to the appropriate type and try again.','File Type Error');
        return;
    end;
end;

%%%% SELECT NAME FOR OUTPUT DATA FILE
[savefilename,savepath] = uiputfile('.mat','ERSPAVG - Select a name for the output file...');

if savefilename == 0
    return;
end;

%%%% ADD FILE AND PATH INFORMATION TO OUTPUT DATA STRUCTURE

ERSP.info.filesAnalyzed = filenames; %add names of analyzed files to structure
ERSP.info.filesPath = pathname; %add path of analyzed files to structure


%%%% CHECK SAMPLING RATE OF ALL FILES TO MAKE SURE THAT THEY ARE THE SAME
if strcmp(filenames{1}(length(filenames{1})-3:length(filenames{1})),'.mat')
    s = load('-mat',[char(pathname),char(filenames{1})],'SampleRate');
else
    s = load('-mat',[char(pathname),char(filenames{1})],'EEG');
    s.SampleRate = s.EEG.srate;
    rmfield(s,'EEG');
end;

for i = 1:size(filenames,2)
    if strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.mat')
        srate = load('-mat',[char(pathname),char(filenames{i})],'SampleRate');
    else
        srate = load('-mat',[char(pathname),char(filenames{i})],'EEG');
        srate.SampleRate = srate.EEG.srate;
        rmfield(srate,'EEG');
    end;

    if s.SampleRate ~= srate.SampleRate 
        errordlg('The sampling rates of all files must be the same. At least one of the files that you selected has a different sampling rate than the others. Please resample the data and try again.','Sampling Rate Error');
        return;
    end;
end;

ERSP.info.srate = s.SampleRate;

%%%% CHECK TIME ARRAYS TO MAKE SURE THAT THEY ARE THE SAME ACROSS SUBJECTS

if strcmp(filenames{1}(length(filenames{1})-3:length(filenames{1})),'.mat')
    s = load('-mat',[char(pathname),char(filenames{1})],'t');
else
    s = load('-mat',[char(pathname),char(filenames{1})],'EEG');
    s.t = s.EEG.times;
    rmfield(s,'EEG');
end;

for i = 1:size(filenames,2)
    if strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.mat')
        t = load('-mat',[char(pathname),char(filenames{i})],'t');
    else
        t = load('-mat',[char(pathname),char(filenames{i})],'EEG');
        t.t = t.EEG.times;
        rmfield(t,'EEG');
    end;

    if ~isequal(reshape(s.t,1,length(s.t)),reshape(t.t,1,length(t.t))) 
        errordlg('The time indices for data points must be the same across all of the selected files. At least one of the time points is different between the data sets. Make sure that the length of segments is equal and the sampling rates are equal for all of the data files. ','Time Index Array Error');
        return;
    end;
end;

timeLimits = [s.t(1) s.t(length(s.t))]; 
ERSP.info.erptimes = s.t;

%%%% FIND ALL CHANNELS THAT OCCUR IN AT LEAST ONE PARTICIPANT AND MAKE
%%%% THESE AVAILABLE FOR SELECTION
ChanNames = '';

for i = 1:size(filenames,2)
    if strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.mat') 
        chans = load('-mat',[char(pathname),char(filenames{i})],'Channels');

        for a = 1:size(chans.Channels,2)
            if length(strfind(ChanNames,[':',chans.Channels(a).Name,':'])) == 0
                ChanNames = [ChanNames,':',chans.Channels(a).Name,':'];
            end;
        end;
    
        ChanNamesIndividualSubjects{i} = ChanNames;
    else
        chans = load('-mat',[char(pathname),char(filenames{i})],'EEG');
        
        for a = 1:size(chans.EEG.chanlocs,2)
            if length(strfind(ChanNames,[':',chans.EEG.chanlocs(a).labels,':'])) == 0
                ChanNames = [ChanNames,':',chans.EEG.chanlocs(a).labels,':'];
            end;
        end;
            
        ChanNamesIndividualSubjects{i} = ChanNames;
    end;
end

ChanNames = strrep(ChanNames,':',' ');
ChanNames = sort(strread(ChanNames, '%s'));


%%%% SELECT THE ELECTRODE PAIRS TO ANALYZE AND SET PROCESSING PARAMETERS


%%%%%SET ROOT UNITS TO CHARACTERS
set(0,'Units','characters');
screenSize = get(0,'ScreenSize');

%%%%% GUI LAYOUT PARAMETERS

bufferSize = 2;
textHeight = 1.5;

buttonAreaHeight = 3;

electrodesPanelWidth = 30;
electrodesPanelHeight = 17;
electrodesPanelX = bufferSize;
electrodesPanelY = buttonAreaHeight;

parametersPanelWidth = 55;
parametersPanelHeight = electrodesPanelHeight;
parametersPanelX = bufferSize+electrodesPanelWidth+bufferSize;
parametersPanelY = buttonAreaHeight;

electrodesBoxWidth = electrodesPanelWidth - 2*bufferSize;
electrodesBoxHeight = electrodesPanelHeight - 2*bufferSize;
electrodesBoxX = electrodesPanelX + bufferSize;
electrodesBoxY = electrodesPanelY + bufferSize;

finishedButtonX = bufferSize;
finishedButtonY = bufferSize/2;
finishedButtonPhrase = 'Continue';
finishedButtonWidth = 2*length(finishedButtonPhrase);
finishedButtonHeight = textHeight;

cancelButtonX = bufferSize + finishedButtonWidth + bufferSize;
cancelButtonY = bufferSize/2;
cancelButtonWidth = 2*length('Cancel');
cancelButtonHeight = textHeight;

decompositionTypeX = bufferSize + electrodesPanelWidth + bufferSize + bufferSize;
decompositionTypeY = buttonAreaHeight +  bufferSize + electrodesBoxHeight - textHeight;
decompositionWidth = parametersPanelWidth - 2*bufferSize;
decompositionHeight = textHeight;

optionalArgumentsX = bufferSize + electrodesPanelWidth + bufferSize + bufferSize;
optionalArgumentsY = parametersPanelY + bufferSize;
optionalArgumentsWidth = decompositionWidth;
optionalArgumentsHeight = decompositionHeight;
optionalArguments = '''plotersp'',''off'',''plotitc'',''off'',''plotphase'',''off'',''verbose'',''off''';

waveletCyclesTextX = optionalArgumentsX;
waveletCyclesTextY = decompositionTypeY - 3.25*textHeight;
waveletCyclesTextWidth = 2*length('Wavelet Cycles');
waveletCyclesTextHeight = textHeight;

waveletCyclesX = optionalArgumentsX + waveletCyclesTextWidth;
waveletCyclesY = decompositionTypeY - 3*textHeight;
waveletCyclesWidth = 6;
waveletCyclesHeight = textHeight;

expansionTextX = optionalArgumentsX;
expansionTextY = decompositionTypeY - 4.5*textHeight;
expansionTextWidth = 1.5*length('Expansion Factor');
expansionTextHeight = 1;

expansionSliderX = expansionTextX + 0.8*expansionTextWidth;
expansionSliderY = decompositionTypeY - 4.5*textHeight;
expansionSliderWidth = 20;
expansionSliderHeight = textHeight;

expansionIndicatorX = expansionSliderX + expansionSliderWidth +  bufferSize;
expansionIndicatorY = decompositionTypeY - 4.5*textHeight;
expansionIndicatorWidth = 6;
expansionIndicatorHeight = 1;


figureHeight = buttonAreaHeight + bufferSize/2 + electrodesPanelHeight;
figureWidth = bufferSize + electrodesPanelWidth + bufferSize + parametersPanelWidth + bufferSize;

figureHandle = figure(...
    'Units','characters',...
    'Position',[(screenSize(3)-figureWidth)/2 (screenSize(4)-figureHeight)/2 figureWidth figureHeight],...
    'MenuBar','none',...
    'Resize','off',...
    'Name','ERSPAVG - Set Analysis Parameters and Select Electrodes',...
    'NumberTitle','off');

if str2num(version('-release')) >= 14
    uipanel(figureHandle,...
        'Units','characters',...
        'Position',[electrodesPanelX electrodesPanelY electrodesPanelWidth electrodesPanelHeight],...
        'Title','Select Electrodes',...
        'BackgroundColor',get(figureHandle,'Color'));

    uipanel(figureHandle,...
        'Units','characters',...
        'Position',[parametersPanelX parametersPanelY parametersPanelWidth parametersPanelHeight],...
        'Title','Analysis Parameters',...
        'BackgroundColor',get(figureHandle,'Color'));
end

electrodeBoxHandle = uicontrol(figureHandle,...
    'Style','listbox',...
    'String',ChanNames,...
    'ToolTipString','Select electrodes to process',...
    'Units','characters',...
    'Position',[electrodesBoxX electrodesBoxY electrodesBoxWidth electrodesBoxHeight],...
    'Max',2);

finishedButtonHandle = uicontrol(figureHandle,...
    'Units','characters',...
    'String',finishedButtonPhrase,...
    'Position',[finishedButtonX finishedButtonY finishedButtonWidth finishedButtonHeight],...
    'Callback', at finishedCallback);

cancelButtonHandle = uicontrol(figureHandle,...
    'Units','characters',...
    'String','Cancel',...
    'Position',[cancelButtonX cancelButtonY cancelButtonWidth cancelButtonHeight],...
    'Callback',{@cancelCallback,figureHandle});


%Wavelet Cylces
uicontrol(figureHandle,...
    'Style','text',...
    'ToolTipString','Number of Cycles in Analysis Wavelets...for more info >>> help timef',...
    'String','Wavelet Cycles',...
    'Units','characters',...
    'Position',[waveletCyclesTextX waveletCyclesTextY waveletCyclesTextWidth waveletCyclesTextHeight],...
    'BackgroundColor',get(figureHandle,'Color'),...
    'HorizontalAlignment','left');
waveletCycleHandle = uicontrol(figureHandle,...
    'Style','edit',...
    'ToolTipString','Number of Cycles in Analysis Wavelets...for more info >>> help timef',...
    'String','0',...
    'Units','characters',...
    'Position',[waveletCyclesX waveletCyclesY waveletCyclesWidth waveletCyclesHeight],...
    'Enable','off');


%Wavelet Expansion Factor
uicontrol(figureHandle,...
    'Style','text',...
    'ToolTipString','Expansion Factor for Analysis Wavelets...for more info >>> help timef',...
    'String','Expansion Factor',...
    'Units','characters',...
    'Position',[expansionTextX expansionTextY expansionTextWidth expansionTextHeight],...
    'BackgroundColor',get(figureHandle,'Color'),...
    'HorizontalAlignment','left');

expansionIndicatorHandle = uicontrol(figureHandle,...
    'Style','text',...
    'ToolTipString','Expansion Factor for Analysis Wavelets...for more info >>> help timef',...
    'Units','characters',...
    'Position',[expansionIndicatorX expansionIndicatorY expansionIndicatorWidth expansionIndicatorHeight],...
    'String','0.5',...
    'BackgroundColor',get(figureHandle,'Color'),...
    'Enable','off');

expansionHandle = uicontrol(figureHandle,...
    'Style','slider',...
    'ToolTipString','Expansion Factor for Analysis Wavelets...for more info >>> help timef',...
    'Units','characters',...
    'Position',[expansionSliderX expansionSliderY expansionSliderWidth expansionSliderHeight],...
    'SliderStep',[0.01 0.1],...
    'Enable','off',...
    'Value',0.5,...
    'Callback',{@expansionSliderCallBack,expansionIndicatorHandle});

%%%%%Decomposition Type and set defaults
uicontrol(figureHandle,...
    'Style','text',...
    'String','Decomposition Method',...
    'Units','characters',...
    'Position',[decompositionTypeX decompositionTypeY decompositionWidth decompositionHeight],...
    'BackgroundColor',get(figureHandle,'Color'),...
    'HorizontalAlignment','left');

decompositionTypeHandle = uicontrol(figureHandle,...
    'Style','popupmenu',...
    'String',{'FFT' 'Wavelet'},...
    'ToolTipString',['Decomposition Method'],...
    'Units','characters',...
    'Position',[decompositionTypeX decompositionTypeY-textHeight decompositionWidth decompositionHeight],...
    'Callback',{@decompositionTypeCallBack,waveletCycleHandle,expansionHandle,expansionIndicatorHandle});

%%%%% Optional Arguments
optionalArgumentsHandle = uicontrol(figureHandle,...
    'Style','edit',...
    'ToolTipString','Optional arguments for TIMEF...for more info >>> help timef',...
    'String',optionalArguments,...
    'Units','characters',...
    'Position',[optionalArgumentsX optionalArgumentsY optionalArgumentsWidth optionalArgumentsHeight],...
    'HorizontalAlignment','left');

uicontrol(figureHandle,...
    'Style','text',...
    'ToolTipString','Optional arguments for TIMEF...for more info >>> help timef',...
    'String','Optional ''timef'' arguments',...
    'Units','characters',...
    'Position',[optionalArgumentsX optionalArgumentsY+textHeight optionalArgumentsWidth optionalArgumentsHeight],...
    'HorizontalAlignment','left',...
    'BackgroundColor',get(figureHandle,'Color'));


uiwait;

if get(cancelButtonHandle,'UserData') == 1
    delete(figureHandle);
    return;
else
    if (get(decompositionTypeHandle,'Value') > 1) 
        typeOfProcessing = [str2num(get(waveletCycleHandle,'String')) get(expansionHandle,'Value')];
        ERSP.info.analysisParameters.type = 'Wavelet';
    else
        typeOfProcessing = 0;
        ERSP.info.analysisParameters.type = 'FFT';
    end;

    electrodeIndices = get(electrodeBoxHandle,'Value');

    electrodeNames = {};
    for i=1:length(electrodeIndices)
        electrodeNames{i} = ChanNames{electrodeIndices(i)};
    end;

    clear ChanNames chans;
    
    optionalArguments = get(optionalArgumentsHandle,'String');

    delete(figureHandle); 
    drawnow;
end


%%%%%% ADD PROCESSING PARAMETERS TO OUTPUT DATA STRUCTURE

ERSP.info.analysisParameters.cycles = typeOfProcessing;
ERSP.info.analysisParameters.optionalArguments = optionalArguments;


%%%%%% ANALYZING THE DATA - COMPUTE INDIVIDUAL SUBJECT ERSPs

fprintf('%s %d %s %d %s \n', 'Computing ERSP for ', size(filenames,2), ' datafiles and ', length(electrodeNames), ' electrodes...');

for i=1:size(filenames,2)
    clear EEG;
    
    if strcmp(filenames{i}(length(filenames{i})-3:length(filenames{i})),'.mat')
        EEG = pop_loadbva(char(filenames(i)));
    else
        EEG = pop_loadset(char(filenames(i)));
    end;
    
    %Convert data to double precision...if already double, this has no effect
    EEG.data = double(EEG.data);
    
    ERSP.subjects(i).numberOfTrials = EEG.trials;
    
    for g = 1:length(electrodeNames)
        found = 0;
        
        for a = 1:length(EEG.chanlocs)
            if strcmp(EEG.chanlocs(a).labels,electrodeNames(g))
                channel = a;
                found = 1;
                
                ERSP.subjects(i).ersp.(char(electrodeNames(g))) = [];
                ERSP.subjects(i).itc.(char(electrodeNames(g))) = [];
                ERSP.subjects(i).powerbaseline.(char(electrodeNames(g))) = [];
                ERSP.subjects(i).Pboot.(char(electrodeNames(g))) = [];
                ERSP.subjects(i).Rboot.(char(electrodeNames(g))) = [];  

                fprintf('%s %s %s %s \n', 'Now Processing Electrode ', char(electrodeNames(g)), ' for data file ', EEG.filename);
                eval(['[ERSP.subjects(i).ersp.(char(electrodeNames(g))),ERSP.subjects(i).itc.(char(electrodeNames(g))),ERSP.subjects(i).powerbaseline.(char(electrodeNames(g))),ERSP.info.times,ERSP.info.freqs,ERSP.subjects(i).Pboot.(char(electrodeNames(g))),ERSP.subjects(i).Rboot.(char(electrodeNames(g)))] = timef(EEG.data(channel,:),EEG.pnts,timeLimits,EEG.srate,typeOfProcessing,',optionalArguments,');'])
                
                ERSP.subjects(i).erp.(char(electrodeNames(g))) = squeeze(mean(EEG.data(channel,:,:),3));
            end
        end  
        
        if found == 0
            fprintf('%s %s %s %s \n', 'Electrode ', char(electrodeNames(g)), ' was not found for data file ', EEG.filename);
        end
    end
end

%%%% COMPUTE THE SUMMARY STATISTICS

fprintf('%s %d %s \n', 'Computing the summary statistics for ', length(electrodeNames), ' electrodes... ');


for g = 1:length(electrodeNames)
    premeanERSP = [];
    premeanITC = [];
    premeanERP = [];
    
    ERSP.summarystats.(char(electrodeNames(g))).numberOfSubjects = 0;
    
    for i = 1:size(filenames,2)
        if isfield(ERSP.subjects(i).ersp,char(electrodeNames(g)))
            premeanERSP(:,:,i) = ERSP.subjects(i).ersp.(char(electrodeNames(g)));
            premeanITC(:,:,i) = ERSP.subjects(i).itc.(char(electrodeNames(g)));
            premeanERP(:,i) = reshape(ERSP.subjects(i).erp.(char(electrodeNames(g))),length(ERSP.subjects(i).erp.(char(electrodeNames(g)))),1);
            numberOfTrialsArray(g,i) = ERSP.subjects(i).numberOfTrials;
            
            ERSP.summarystats.(char(electrodeNames(g))).numberOfSubjects = ERSP.summarystats.(char(electrodeNames(g))).numberOfSubjects + 1;
            ERSP.summarystats.(char(electrodeNames(g))).subjectsIncluded(ERSP.summarystats.(char(electrodeNames(g))).numberOfSubjects) = i;
        end 
    end
    
    ERSP.summarystats.(char(electrodeNames(g))).ersp.mean = mean(premeanERSP,3);
    ERSP.summarystats.(char(electrodeNames(g))).ersp.median = median(premeanERSP,3);
    ERSP.summarystats.(char(electrodeNames(g))).ersp.sd = std(premeanERSP,0,3);
    
    ERSP.summarystats.(char(electrodeNames(g))).itc.mean = mean(premeanITC,3);
    ERSP.summarystats.(char(electrodeNames(g))).itc.median = median(premeanITC,3);
    ERSP.summarystats.(char(electrodeNames(g))).itc.sd = std(premeanITC,0,3);
    
    ERSP.summarystats.(char(electrodeNames(g))).erp.mean = mean(premeanERP,2);
    ERSP.summarystats.(char(electrodeNames(g))).erp.median = median(premeanERP,2);
    ERSP.summarystats.(char(electrodeNames(g))).erp.sd = std(premeanERP,0,2);
    
    ERSP.summarystats.(char(electrodeNames(g))).averageNumberOfTrials = mean(squeeze(numberOfTrialsArray(g,:)));
end;

save([savepath, savefilename],'ERSP');




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% CALLBACK FUNCTION DEFINITIONS %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function finishedCallback(src,event)

uiresume;

function cancelCallback(src,event,figureHandle)

set(src,'UserData',1);
uiresume;

function expansionSliderCallBack(src,event,expansionIndicatorHandle)

set(expansionIndicatorHandle,'String',num2str(get(src,'Value')));

function decompositionTypeCallBack(decompositionTypeHandle,event,waveletCycleHandle,expansionHandle,expansionIndicatorHandle)

if (get(decompositionTypeHandle,'Value')) == 1
    set(waveletCycleHandle,'Enable','off');
    set(expansionHandle,'Enable','off');
    set(expansionIndicatorHandle,'Enable','off');
    set(waveletCycleHandle,'String','0');
elseif (get(decompositionTypeHandle,'Value')) == 2
    set(waveletCycleHandle,'Enable','on'); 
    set(expansionHandle,'Enable','on'); 
    set(expansionIndicatorHandle,'Enable','on');
    set(waveletCycleHandle,'String','3'); 
end;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ADDTIONAL FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [filenames, pathname] = uiGetFilesJava
% This is a Java interfaced version of UIGETFILES, that brings multiple file
% open dialog box. 
%
% [filenames, pathname] = uigetfiles; displays a dialog box file browser
% from which the user can select multiple files.  The selected files are
% returned to FILENAMES as an arrayed strings. The directory containing
% these files is returned to PATHNAME as a string. 
%
% A successful return occurs only if the files exist.  If the user selects
% a  file that does not exist, an error message is displayed to the command
% line.  If the Cancel button is selected, zero is assigned to FILENAMES
% and current directory is assigned to PATHNAME. 
% 
% This program has an equivalent function to that of a C version of
% "uigetfiles.dll" downloadable from www.mathworks.com under support, file
% exchange (ID: 331). 
%
% It should work for matlab with Java 1.3.1 or newer.
%
% Shanrong Zhang
% Department of Radiology
% University of Texas Southwestern Medical Center
% 02/09/2004
%
% email: shanrong.zhang at utsouthwestern.edu

% mainFrame = com.mathworks.ide.desktop.MLDesktop.getMLDesktop.getMainFrame;
filechooser = javax.swing.JFileChooser(pwd);
filechooser.setMultiSelectionEnabled(true);
filechooser.setFileSelectionMode(filechooser.FILES_ONLY);
selectionStatus = filechooser.showOpenDialog(com.mathworks.mwswing.MJFrame); 

if selectionStatus == filechooser.APPROVE_OPTION
    pathname = [char(filechooser.getCurrentDirectory.getPath), ...
                java.io.File.separatorChar];
    selectedfiles = filechooser.getSelectedFiles;
    for k = 1:1:size(selectedfiles)
        filenames(k) = selectedfiles(k).getName;
    end
    filenames = char(filenames);  
else
    pathname = pwd;
    filenames = 0;
end

% End of code







More information about the eeglablist mailing list