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

📄 eeg_crosshair.m

📁 Matlab下的EEG处理程序库
💻 M
📖 第 1 页 / 共 4 页
字号:
    case 1
        % Given that xdata & ydata are the same length arrays,
        % we can find the ypoint given the nearest xpoint.
        [H.data.xindex, H.data.xpoint] = NearestXYArrayPoint( xdata, H.data.xpoint );
        H.data.ypoint = ydata(H.data.xindex);
    case 2
        H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'nearest' );
    case 3
        H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'linear' );
    case 4
        H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'spline' );
    case 5
        H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'cubic' );
    otherwise
        %use default (linear in matlabR12)
        H.data.ypoint = interp1( xdata, ydata, H.data.xpoint );
    end

return

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ Yall ] = interpYall( H )
    
    xdata = H.data.xdata(:,H.data.yindex);
    Yall  = H.data.ydata;
    
    if      H.data.xpoint >= max(xdata),
            H.data.xpoint  = max(xdata);
            H.data.xindex  = find(xdata == max(xdata));
            Yall = ydata(:,H.data.xindex);
            return;
    elseif  H.data.xpoint <= min(xdata),
            H.data.xpoint  = min(xdata);
            H.data.xindex  = find(xdata == min(xdata));
            Yall = ydata(:,H.data.xindex);
            return;
    end
    
    % 'none|nearest|linear|spline|cubic'
    interp = get(H.handles.interp,'Value');
    
    switch interp,
    case 1
        % do nothing in this case
    case 2
        Yall = interp1( xdata, Yall, H.data.xpoint, 'nearest' );
    case 3
        Yall = interp1( xdata, Yall, H.data.xpoint, 'linear' );
    case 4
        Yall = interp1( xdata, Yall, H.data.xpoint, 'spline' );
    case 5
        Yall = interp1( xdata, Yall, H.data.xpoint, 'cubic' );
    otherwise
        %use default (linear in matlabR12)
        Yall = interp1( xdata, Yall, H.data.xpoint );
    end

return

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ index, point ] = NearestXYArrayPoint( data_array, point, type )
    
    if ~exist('type','var') type = ''; end

    % In this function, input data_array is an array, not a matrix.
    % This function returns the data point in the array
    % that has the closest value to the value given (point).  In
    % the context of 'eeg_crosshair' the point is a mouse position.
    
    if      point >= max(data_array)
            point  = max(data_array);
            index  = find(data_array == point);
            return;
    elseif  point <= min(data_array)
            point  = min(data_array);
            index  = find(data_array == point);
            return;
    end
    
    data_sorted = sort(data_array);
    
    greater = find(data_sorted > point);
    greater_index = greater(1);
    
    lesser = find(data_sorted < point);
    lesser_index = lesser(end);
    
    greater_dif = data_sorted(greater_index) - point;
    lesser_dif  = point - data_sorted(lesser_index);
    
    if     strcmp(type,'exact'),  index = find(data_array == point);
    elseif strcmp(type,'nextx'),  index = greater_index;
    elseif strcmp(type,'prevx'),  index = lesser_index;
    else
        if (greater_dif < lesser_dif)
            index = find(data_array == data_sorted(greater_index));
        else
            index = find(data_array == data_sorted(lesser_index));
        end
    end
    point = data_array(index);
    
return


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ xpoint, xindex, ypoint, yindex ] = NearestXYMatrixPoint( Xdata, Ydata, xpoint, ypoint )

    % In this function, Xdata & Ydata are matrices of the same dimensions.
    % This function attempts to find the nearest values in Xdata & Ydata
    % to the mouse position (xpoint, ypoint).
    
    % It is assumed that Xdata has identical columns, so we only really
    % need the first column to find the nearest value to xpoint.
    
    [ xindex, xpoint ] = NearestXYArrayPoint( Xdata(:,1), xpoint );
    
    % Now, given the xpoint, we can select just that row of the
    % Ydata matrix corresponding to the xpoint.
    ydata = Ydata(xindex,:);
    
    % The ydata array is searched in same manner as the xdata
    % array for the nearest value.
    [ yindex, ypoint ] = NearestXYArrayPoint( ydata, ypoint );
    
return


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H] = INIT
    
    H.gui = gcf;          % Get current figure handle
    
    % Match background figure colour
    bgcolor = get(H.gui,'Color');
    % Try to adapt the foreground colour a little
    black = find(bgcolor <= .6);
    fgcolor = [0 0 0]; %black text
    if length(black)>2, fgcolor = [1 1 1]; end
    
    
    H.handles.axis = gca; % Get current axis handles
    axis tight;
    set(H.handles.axis,'YDir','reverse');
    H.handles.ylim = get(H.handles.axis,'ylim');
    
    % enable right click access to eeg_crosshair
    if isempty(get(H.handles.axis,'uicontextmenu')),
        amenu=uicontextmenu;
        a=uimenu(amenu,'Label','Crosshair','Callback','eeg_crosshair; ');
        set(H.handles.axis,'uicontextmenu',amenu);
    end
    
    % store current button fcn
    H.handles.button = get(H.gui,'WindowButtonDownFcn');
    % set XHR button down fcn
    set(H.gui,'WindowButtonDownFcn','[Xpoint,Ypoint] = eeg_crosshair(''down'');');
    set(H.gui,'KeyPressFcn','[Xpoint,Ypoint] = eeg_crosshair(''keypress'');');
    
    Font.FontName   = 'Helvetica';
    Font.FontUnits  = 'Pixels';
    Font.FontSize   = 10;
    Font.FontWeight = 'normal';
    Font.FontAngle  = 'normal';
    
    
    H.handles.yflip       =   uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
                              'Position',[.00 .70 .08 .05],...
                              'Tag','YFLIP',...
                              'TooltipString','Flip Y Axis', ...
                              'String','Flip',...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'ydir = get(XHR.handles.axis,''YDir'');',...
                                                'if isequal(ydir,''normal''),',...
                                                '   set(XHR.handles.axis,''YDir'',''reverse'');',...
                                                'else,',...
                                                '   set(XHR.handles.axis,''YDir'',''normal'');',...
                                                'end;',...
                                                'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
    
    H.handles.yreset      =   uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
                              'Position',[.00 .65 .08 .05],...
                              'Tag','YRESET',...
                              'TooltipString','Reset Axis Limits', ...
                              'String','Reset',...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'axis tight;',...
                                                'XHR.handles.ylim = get(XHR.handles.axis,''ylim'');',...
                                                'set(XHR.handles.ymin,''string'',sprintf(''%7.1f'',XHR.handles.ylim(1)));',...
                                                'set(XHR.handles.ymax,''string'',sprintf(''%7.1f'',XHR.handles.ylim(2)));',...
                                                'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
    
    H.handles.ymin        =   uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.00 .60 .08 .05],...
                              'HorizontalAlign','left',...
                              'Tag','YMIN',...
                              'TooltipString','Set Y min', ...
                              'String',sprintf('%7.1f',H.handles.ylim(1)),...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'ymin = str2num(get(XHR.handles.ymin,''string''));',...
                                                'XHR.handles.ylim(1) = ymin;',...
                                                'set(XHR.handles.axis,''ylim'',XHR.handles.ylim);',...
                                                'set(XHR.handles.ymin,''string'',sprintf(''%7.1f'',XHR.handles.ylim(1)));',...
                                                'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR ymin;'));
    
    H.handles.ymax        =   uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.00 .55 .08 .05],...
                              'HorizontalAlign','left',...
                              'Tag','YMAX',...
                              'TooltipString','Set Y max', ...
                              'String',sprintf('%7.1f',H.handles.ylim(2)),...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'ymax = str2num(get(XHR.handles.ymax,''string''));',...
                                                'XHR.handles.ylim(2) = ymax;',...
                                                'set(XHR.handles.axis,''ylim'',XHR.handles.ylim);',...
                                                'set(XHR.handles.ymax,''string'',sprintf(''%7.1f'',XHR.handles.ylim(2)));',...
                                                'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR ymax;'));
    
    H.handles.grid        =   uicontrol(H.gui,'Style','checkbox','Units','Normalized',Font,...
                              'Position',[.00 .50 .08 .05],...
                              'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
                              'Tag','GRID',...
                              'TooltipString','Toggle plot grid on/off.', ...
                              'String','grid',...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'grid(XHR.handles.axis);',...
                                                'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
    
    H.handles.xvalue      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.13 .95 .15 .05],...
                              'Tag','XVALUE',...
                              'TooltipString','X value (Read Only)',...
                              'BackGroundColor',[ 0 .7 .7],'String',' ');
    H.handles.yvalue      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.28 .95 .15 .05],...
                              'Tag','YVALUE',...
                              'TooltipString','Y value (Read Only)',...
                              'BackGroundColor',[ 0 .7 .7],'String',' ');
    
    H.handles.yindex      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.92 .87 .08 .05],...
                              'BackGroundColor',[ 0 .7 .7],...
                              'Tag','YINDEX',...
                              'TooltipString','Enter Y index into plot data matrix.  Same as trace number.',...
                              'String','1',...
                              'Value',1,...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'yi = str2num(get(XHR.handles.yindex,''String''));',...
                                                'XHR.data.yindex = yi;',...
                                                'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR yi; ',...
                                                '[Xpoint,Ypoint] = eeg_crosshair(''changey'');'));
    H.handles.yprev       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
                              'Position',[.92 .82 .04 .05],...
                              'String','<',...
                              'Tag','YPREV',...
                              'TooltipString','Goto Previous Y Index (channel).',...
                              'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''prevy'');');
    H.handles.ynext       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
                              'Position',[.96 .82 .04 .05],...
                              'String','>',...
                              'Tag','YNEXT',...
                              'TooltipString','Goto Next Y Index (channel).',...
                              'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''nexty'');');
    H.handles.yLT         = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
                              'Position',[.92 .77 .04 .05],...
                              'String','LT',...
                              'Tag','YLT',...
                              'TooltipString','Goto next Y Less Than current Y.',...
                              'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''yLT'');');
    H.handles.yGT         = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
                              'Position',[.96 .77 .04 .05],...
                              'String','GT',...
                              'Tag','YGT',...
                              'TooltipString','Goto next Y Greater Than current Y.',...
                              'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''yGT'');');
    
    H.handles.xindex      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
                              'Position',[.92 .70 .08 .05],...
                              'BackGroundColor',[ 0 .7 .7],...
                              'Tag','XINDEX',...
                              'TooltipString','Enter X index into plot data matrix.  Only available for interpolation = ''none''.',...
                              'String','1',...
                              'Value',1,...
                              'Callback',strcat('XHR = get(gcbf,''userdata'');',...
                                                'xi = str2num(get(XHR.handles.xindex,''String''));',...
                                                'XHR.data.xindex = xi;',...
                                                'set(XHR.handles.xinterp,''value'',0); ',...
                                                'set(XHR.handles.xinterp,''string'',''0''); ',...
                                                'set(XHR.handles.interp, ''value'',1); ',...
                                                'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; ',...
                                                '[Xpoint,Ypoint] = eeg_crosshair(''changex'');'));
    H.handles.xprev       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
                              'Position',[.92 .65 .04 .05],...
                              'String','<',...
                              'Tag','XPREV',...
                              'TooltipString','Goto Previous X Index (no interpolation).',...
                              'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''prevx'');');

⌨️ 快捷键说明

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