⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_eeg_open.m

📁 Matlab下的EEG处理程序库
💻 M
字号:
function [p] = gui_eeg_open(p,eeg_open_command,parent)

% GUI_EEG_OPEN - Load an EEG data file into matlab workspace
% 
% Useage: [p] = gui_eeg_open(p,[command],[parent])
%
% p is a structure, generated by 'eeg_toolbox_defaults'
% command is either 'init' or 'load'
% parent is a handle to the gui that calls this gui, useful
% for updating the UserData field of the parent from this gui.
% The p structure is returned to the parent when the parent 
% handle is given.
%

% $Revision: 1.3 $ $Date: 2003/04/07 06:12:02 $

% Licence:  GNU GPL, no express or implied warranties
% History:  01/2002, Darren.Weber@flinders.edu.au
%           08/2002, Darren.Weber@flinders.edu.au
%                    added EMSE avg handling
%                    added interpolation of zero point option
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~exist('eeg_open_command','var'), eeg_open_command = 'init'; end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paint the GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

switch eeg_open_command,
    
case 'init',

    if exist('parent','var'),
        EEGOpen = INIT(p,parent);
    else
        EEGOpen = INIT(p,'');
    end
    
case 'plot',

    EEGOpen = get(gcbf,'Userdata');
    
    EEGOpen.p = eeg_open(EEGOpen.p,EEGOpen.gui);
    set(EEGOpen.gui,'Userdata',EEGOpen); % update GUI with voltage data & parameters
    
    p = gui_updateparent(EEGOpen,0);
    
    if isequal(get(EEGOpen.handles.Bhold,'Value'),0),
        close gcbf;
        if isfield(EEGOpen,'parent'),
            parent = EEGOpen.parent.gui;
        else
            parent = [];
        end
    else
        parent = EEGOpen.gui;
    end
    
    plotfig = figure('Name',EEGOpen.p.volt.file,...
                     'NumberTitle','off',...
                     'UserData',EEGOpen.p);
    movegui(plotfig,'center');
    
    plot(EEGOpen.p.volt.timeArray,EEGOpen.p.volt.data); axis tight;
    eeg_plot_metric;
    
    if isempty(parent), [Xpoint,Ypoint] = eeg_crosshair('init',EEGOpen.p);
    else                [Xpoint,Ypoint] = eeg_crosshair('init',EEGOpen.p,parent);
    end
    
case 'save',
    
    fprintf('\nGUI_EEG_OPEN: Save As not implemented yet.\n');
    
case 'return',
    
    EEGOpen = get(gcbf,'Userdata');
    
    set(EEGOpen.gui,'Pointer','watch');
    
    EEGOpen.p = eeg_open(EEGOpen.p);
    
    set(EEGOpen.gui,'Pointer','arrow');
    
    if isequal(get(EEGOpen.handles.Bhold,'Value'),1),
        p = gui_updateparent(EEGOpen,0);
    else
        p = gui_updateparent(EEGOpen);
        close gcbf;
    end
    
otherwise,
    
    EEGOpen = get(gcbf,'Userdata');
    GUI.parent = EEGOpen.parent;
    gui_updateparent(GUI);
    close gcbf;
    
end

return



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [EEGOpen] = INIT(p,parent)
    % GUI General Parameters
    
    GUIwidth  = 500;
    GUIheight = 120;
    
    GUI = figure('Name','EEG File Open (avg only)','Tag','EEG_OPEN',...
                 'NumberTitle','off',...
                 'MenuBar','none','Position',[1 1 GUIwidth GUIheight]);
    movegui(GUI,'center');
    
    Font.FontName   = 'Helvetica';
    Font.FontUnits  = 'Pixels';
    Font.FontSize   = 12;
    Font.FontWeight = 'normal';
    Font.FontAngle  = 'normal';
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Voltage Data Selection and Parameters

    G.Title_data = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .75 .17 .2],...
        'String','Data Type:','HorizontalAlignment','left');
    
    switch p.volt.type
        case 'ASCII',   voltType = 1;
        case 'EMSE',    voltType = 2;
        case 'Scan41',  voltType = 3;
        case 'Scan3x',  voltType = 4;
        case 'Matlab',  voltType = 5;
        otherwise,      voltType = 1;
    end
    G.PvoltType = uicontrol('Tag','PvoltType','Parent',GUI,'Style','popupmenu',...
        'Units','Normalized',Font,  ...
        'Position',[.20 .75 .2 .2],...
        'String',{'ASCII' 'EMSE' 'Scan41' 'Scan3x' 'Matlab'},'Value',voltType,...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'EEGOpen.p.volt.type = popupstr(EEGOpen.handles.PvoltType);',...
                          'set(gcbf,''Userdata'',EEGOpen); clear EEGOpen;'));
    
    % ERP Parameters
    G.Bascii = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.45 .75 .2 .2],...
        'String','ERP Parameters','BusyAction','queue',...
        'BackgroundColor',[0.0 0.0 0.75],...
        'ForegroundColor',[1 1 1], 'HorizontalAlignment', 'center',...
        'Callback','tempgui = gui_eeg_ascii_parameters(gcbf); clear tempgui;');
    
    % Interpolate Zero
	G.BinterpZero = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
        'Position',[.80 .75 .18 .2],'String','Interp 0','BusyAction','queue',...
        'TooltipString','Interpolate zero, mainly for ascii, scan3x, scan4x files.',...
        'Value',p.volt.interpZero,'HorizontalAlignment', 'center',...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'EEGOpen.p.volt.interpZero = get(EEGOpen.handles.BinterpZero,''Value''); ',...
                          'set(gcbf,''Userdata'',EEGOpen); clear EEGOpen;'));
    
    G.Title_path = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .50 .17 .2],...
        'String','Path','HorizontalAlignment','left');
    G.EvoltPath = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
    	'Position',[.20 .50 .58 .2], 'String',p.volt.path,...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'EEGOpen.p.volt.path = get(EEGOpen.handles.EvoltPath,''String'');',...
                          'set(gcbf,''Userdata'',EEGOpen); clear EEGOpen;'));
    
    G.Title_file = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
        'Position',[.01 .25 .17 .2],...
        'String','File','HorizontalAlignment','left');
    G.EvoltFile = uicontrol('Parent',GUI,'Style','edit','Units','Normalized',Font,  ...
    	'Position',[.20 .25 .58 .2], 'String',p.volt.file,...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'EEGOpen.p.volt.file = get(EEGOpen.handles.EvoltFile,''String'');',...
                          'set(gcbf,''Userdata'',EEGOpen); clear EEGOpen;'));
    
    Font.FontWeight = 'bold';
    
    % BROWSE: Look for the data
    browsecommand = strcat('EEGOpen = get(gcbf,''Userdata'');',...
        'cd(EEGOpen.p.volt.path);',...
        '[file, path] = uigetfile(',...
        '{''*.dat;*.asc;*.txt'', ''ASCII Data Files (*.dat,*.asc,*.txt)'';', ...
        ' ''*.avg'', ''NeuroScan & EMSE Averages (*.avg)'';', ...
        ' ''*.mat'', ''MATLAB Data Files (*.mat)'';', ...
        ' ''*.*'',   ''All Files (*.*)''},', ...
        '''Select ERP File'');',...
        'if ~isequal(path,0), EEGOpen.p.volt.path = path; end;',...
        'if ~isequal(file,0), EEGOpen.p.volt.file = file; end;',...
        'set(EEGOpen.handles.EvoltPath,''String'',EEGOpen.p.volt.path);',...
        'set(EEGOpen.handles.EvoltFile,''String'',EEGOpen.p.volt.file);',...
        'if ~isempty(findstr(file,''.dat'')) | ~isempty(findstr(file,''.txt'')) | ~isempty(findstr(file,''.asc'')), ',...
            'set(EEGOpen.handles.PvoltType,''Value'',1); ',...
            'EEGOpen.p.volt.type = popupstr(EEGOpen.handles.PvoltType);',...
        'elseif ~isempty(findstr(file,''.avg'')), ',...
            'set(EEGOpen.handles.PvoltType,''Value'',2); ',...
            'EEGOpen.p.volt.type = popupstr(EEGOpen.handles.PvoltType);',...
        'else, ',...
            'set(EEGOpen.handles.PvoltType,''Value'',4); ',...
            'EEGOpen.p.volt.type = popupstr(EEGOpen.handles.PvoltType);',...
        'end;',...
        'set(gcbf,''Userdata'',EEGOpen); clear EEGOpen file path;');
    G.BvoltFile = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized',Font, ...
        'Position',[.01 .01 .17 .2], 'String','BROWSE',...
        'BackgroundColor',[0.8 0.8 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback', browsecommand );
    
    % PLOT: Load & plot the data!
    G.Bplot = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.20 .01 .18 .2],...
        'String','PLOT','BusyAction','queue',...
        'TooltipString','Plot the EEG data and return p struct.',...
        'BackgroundColor',[0.0 0.5 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'p = gui_eeg_open(EEGOpen.p,''plot'');',...
                          'clear EEGOpen;'));

    % Save As
	G.Bsave = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.40 .01 .18 .2],'HorizontalAlignment', 'center',...
        'String','SAVE AS','TooltipString','EEG File Conversion Tool (not implemented yet)',...
        'BusyAction','queue',...
        'Visible','on',...
        'BackgroundColor',[0.0 0.0 0.75],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'p = gui_eeg_open(EEGOpen.p,''save'');',...
                          'clear EEGOpen;'));

    % Quit, return file parameters
    G.Breturn = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.60 .01 .18 .2],...
        'String','RETURN','BusyAction','queue',...
        'TooltipString','Return p struct to workspace and parent GUI.',...
        'BackgroundColor',[0.75 0.0 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback',strcat('EEGOpen = get(gcbf,''Userdata'');',...
                          'p = gui_eeg_open(EEGOpen.p,''return'');',...
                          'clear EEGOpen;'));
    
    % Cancel
    G.Bcancel = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
        'Position',[.80 .01 .18 .2],...
        'String','CANCEL','BusyAction','queue',...
        'TooltipString','Close, do not return parameters.',...
        'BackgroundColor',[0.75 0.0 0.0],...
        'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
        'Callback','gui_eeg_open([],''cancel'');');
    
    % Hold GUI Open checkbox
	G.Bhold = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
        'Position',[.80 .25 .18 .2],'String','Hold GUI','BusyAction','queue',...
        'TooltipString','EEG File Load GUI remains open after ''Plot'' or ''Return'' commands.',...
        'Value',p.hold,'HorizontalAlignment', 'center');
    
    
    % Store userdata
    if exist('parent','var'), EEGOpen.parent.gui = parent; end
    EEGOpen.gui = GUI;          
    EEGOpen.handles = G;
    EEGOpen.p = p;
    set(GUI,'Userdata',EEGOpen);
    set(GUI,'HandleVisibility','callback');
    
return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -