crosshair_subplots.m

来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 1,124 行 · 第 1/3 页

M
1,124
字号
function [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);%  CROSSHAIR:  A gui interface for reading (x,y) values from a plot.%  %  [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);%  %  A set of mouse driven crosshairs is placed on the current axes,%  and displays the current (x,y) values of the line plot.  There is an%  option to provide data specific values or interpolated values.  The%  resolution of the data specific values depends on both the data%  resolution and the GUI interface (mainly mouse movement resolution).%  The interpolated values appear to provide a more continuous function,%  however they too depend on the GUI interface resolution.  There are %  no options for extrapolation.%  %  For multiple traces, plots with the same length(xdata) are%  tracked. Each mouse click returns Xpoint,Ypoint values and selecting %  'done' will remove the GUI and restore the mouse buttons to previous %  values.  Selecting 'exit' will remove the GUI and close the figure.%  %  In this version (Dec 2002), the crosshairs can track multiple subplots%  and there are new options to define functions of X/Y and monitor %  their results.  There is also a new STORE button that creates and %  updates an XYhist struct in the base workspace, which contains value %  labels and values.  This version has better controls of X/Y movements, %  including better interpolation movement options.  This version attempts %  to respond correctly to keyboard entries, including TAB between subplots,%  RETURN to 'save', ESC for 'done' and all the arrow keys to move the%  crosshairs.%  %  Some further help is given in the tool tips of the GUI.%%  Note: crosshair should always update the Xpoint,Ypoint in the base %  workspace. Here is an example of how to get return values within%  a script/function after pressing the exit button of crosshair:%       function [X,Y] = crosshair_returnXY%		x = [1:10]; y(1,:) = sin(x); y(2,:) = cos(x);%		figure; plot(x,y); crosshair;%		uiwait%		X = evalin('base','Xpoint');%		Y = evalin('base','Ypoint');%		return%  Copy this text to a function .m file and then call it from the%  base workspace with [X,Y] = crosshair_returnXY%  %  Useage:  wt=0:0.01:2.5*pi;%           t=wt;%           subplot(2,1,1),plot(t,1.0*sin(wt),t,1.0*sin(wt-110/180*pi),t,1.0*sin(wt-250/180*pi));%           subplot(2,1,2), plot(t,sin(2*wt));%           crosshair_subplots;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (C) 2002  Darren L. Weber% % This program is free software; you can redistribute it and/or% modify it under the terms of the GNU General Public License% as published by the Free Software Foundation; either version 2% of the License, or (at your option) any later version.% % This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.%  History: 03/96, Richard G. Cobb <cobbr@plk.af.mil>%           08/01, Darren.Weber@flinders.edu.au%                  replaced obsolete 'table1' with 'interp1'; fixed bug%                  with number of 'traces'; rationalized calculations into%                  a common subfunction for x,y point calc in 'down','up', %                  & 'move' button functions; added option to turn on/off%                  interpolation and the exit button; simplified updates %                  to graphics using global GUI handle structure.%           11/01, Darren.Weber@flinders.edu.au%                  added tooltips for several GUI handles%                  added multiple interpolation methods%                  added GUI for data matrix indices (given no interpolation)%                  added option to select trace nearest to mouse click point%                  reversed order of lines in data matrix to be consistent%                    with the value returned from the nearest trace subfunction%                  create crosshair lines after finding all plot lines to%                    avoid confusing them with the plot lines%           01/02, Darren.Weber@flinders.edu.au%                  should now work across multiple plot figures, given%                    that all gui handles and data are now stored in the%                    plot figure 'userdata' handle.%                  added functionality to move smoothly from interpolation%                    back to the delimited data via the "next/previous" %                    buttons.%           06/02, Darren.Weber@flinders.edu.au%                  learned how to get values back to a script/function with%                    evalin command and updated help above.%           12/02, Darren.Weber@flinders.edu.au%                  added Store uicontrol and associated XYhist variable %                   updates in base workspace to provide storage of %                   consecutive XY values (thanks to C.A.Swenne@lumc.nl &%                   H.van_de_Vooren@lumc.nl for their suggestion/assistance).%                  added keyboard controls to left/right arrow and return.%                  added prev/next X interpolation interval.%                  added handling of subplots in crosshair_subplots version.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~exist('action','var')     action = 'init';elseif isempty(action)    action = 'init';endXHR_HANDLES = get(gcf,'userdata');if gca & ~isempty(XHR_HANDLES),    if ~isequal(gca,XHR_HANDLES.axis),        % Ensure we have the right axis data        XHR_HANDLES.axis = gca;        XHR_HANDLES.data = get_data;    endend% Check for specific keys and assign reasonable actionsif strcmp(action, 'keypress'),        CC = get(XHR_HANDLES.gui,'CurrentCharacter');    cc = double(CC);    if cc,        switch cc,        case  9, action = 'axes';       % TAB, switch axes, if possible        case 27, action = 'done';       % ESC        case 28, action = 'prevx';      % left        case 29, action = 'nextx';      % right        case 30, action = 'ygt';        % up        case 31, action = 'ylt';        % down        case 13, action = 'store';      % return/enter        otherwise, action = 'up';       % all other keys        end    endendaction = lower(action);switch action,case 'init',        % Paint GUI    XHR_HANDLES = INIT;        % Update and return values    XHR_HANDLES = updateDATA(XHR_HANDLES);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);    case 'axes',        % TAB between axes in subplots of a figure    ax = findobj(gcf,'type','axes');    if length(ax) > 1,        nax = find(ax == gca);        if nax < length(ax),            axes(ax(nax+1));        else            axes(ax(1));        end    end    XHR_HANDLES.axis = gca;    XHR_HANDLES.data = get_data;    XHR_HANDLES = updateGUI(XHR_HANDLES);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    % Mouse Click Downcase 'down',        set(XHR_HANDLES.gui,'WindowButtonMotionFcn','crosshair_subplots(''move'');');    set(XHR_HANDLES.gui,'WindowButtonUpFcn','[Xpoint,Ypoint] = crosshair_subplots(''up'');');        XHR_HANDLES = updateDATA(XHR_HANDLES);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);    % Mouse Drag Motioncase 'move',        XHR_HANDLES = updateDATA(XHR_HANDLES);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);    % Mouse Click Upcase 'up',        set(XHR_HANDLES.gui,'WindowButtonMotionFcn',' ');    set(XHR_HANDLES.gui,'WindowButtonUpFcn',' ');        XHR_HANDLES = updateDATA(XHR_HANDLES);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);    % Next or Previous X pointcase {'nextx','prevx','changex','nexty','prevy','changey','ylt','ygt'}, % Change X/Y        XHR_HANDLES = moveXY(XHR_HANDLES,action);    Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);    % Store XY values into a history arraycase 'store',        Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    updateXYhistory(XHR_HANDLES);    % Exit crosshairs GUIcase {'done','exit'},        Xpoint = get(XHR_HANDLES.xvalue,'Value');    Ypoint = get(XHR_HANDLES.yvalue,'Value');    %updateXYhistory(Xpoint,Ypoint);        handles = fieldnames(XHR_HANDLES);    for i=1:length(handles),        switch handles{i},        case {'axis','datalines','gui'},        otherwise,            h = getfield(XHR_HANDLES,handles{i});            if ishandle(h), delete(h); end        end    end        if strcmp(action,'exit');        if ishandle(XHR_HANDLES.gui),            close(XHR_HANDLES.gui);        end    else                lines = findobj(gcf,'tag','XHR_XLINE');        for l = 1:length(lines),            line = lines(l);            if ishandle(line), delete(line); end        end        lines = findobj(gcf,'tag','XHR_YLINE');        for l = 1:length(lines),            line = lines(l);            if ishandle(line), delete(line); end        end                set(XHR_HANDLES.gui,'WindowButtonUpFcn','');        set(XHR_HANDLES.gui,'WindowButtonMotionFcn','');        set(XHR_HANDLES.gui,'WindowButtonDownFcn',' ');                refresh(XHR_HANDLES.gui);    end        clear XHR_HANDLES;    return;    endif ishandle(XHR_HANDLES.axis),    set(XHR_HANDLES.axis,'userdata',XHR_HANDLES.data);endif ishandle(XHR_HANDLES.gui),    set(XHR_HANDLES.gui,'userdata',XHR_HANDLES);    figure(XHR_HANDLES.gui);endreturn;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function updateXYhistory(H),        Ch = get(H.yindex,'Value');    X  = get(H.xvalue,'Value');    Y  = get(H.yvalue,'Value');    fX = get(H.fxvalue,'Value');    fY = get(H.fyvalue,'Value');        fXeq = get(H.fxeq,'String');    fYeq = get(H.fyeq,'String');        XY.labels = {'Channel','X','Y',['f(x) = ',fXeq],['f(y) = ',fYeq]};    XY.data   = [Ch,X,Y,fX,fY];        if evalin('base','exist(''XYhist'',''var'');'),        XYhist = evalin('base','XYhist');        % get the current history set        set = getfield(XYhist,['set',num2str(XYhist.set)]);        if isequal(set.labels,XY.labels),            set.data(end+1,:) = XY.data;            XYhist = setfield(XYhist,['set',num2str(XYhist.set)],set);            assignin('base','XYhist',XYhist);        else            fprintf('\nWarning: creating new set of XYhist in base workspace.\n\n');            XYhist.set = XYhist.set + 1;            XYhist = setfield(XYhist,['set',num2str(XYhist.set)],XY);            assignin('base','XYhist',XYhist);        end    else        XYhist.set = 1;        XYhist.set1 = XY;        assignin('base','XYhist',XYhist);    end    return%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function [H] = moveXY(H,move)        interp  = get(H.interp,'Value');    xinterp = get(H.xinterp,'Value');        if (xinterp > 0) & (interp > 1),                % Use incremental interpolation of x values        switch move,        case 'nexty', H.data.yindex = H.data.yindex + 1;        case 'prevy', H.data.yindex = H.data.yindex - 1;        case 'ygt',            ydata = interpYall(H);            [ysort,yi] = sort(ydata);            currYI = find(ysort > H.data.ypoint);            if min(currYI),                H.data.yindex = yi(min(currYI));            end        case 'ylt',            ydata = interpYall(H);            [ysort,yi] = sort(ydata);            currYI = find(ysort < H.data.ypoint);            if max(currYI),                H.data.yindex = yi(max(currYI));            end        case 'nextx',            H.data.xpoint = H.data.xpoint + xinterp;        case 'prevx',            H.data.xpoint = H.data.xpoint - xinterp;        end        H = checkdatarange(H);        H = interpY(H);        updateGUI(H);        return    end            % No interpolation of x values...        if (interp > 1)        xdata = H.data.xdata(:,H.data.yindex);        [H.data.xindex] = NearestXYArrayPoint( xdata, H.data.xpoint, move );    end        switch move,    case 'nextx',        % Increase current xindex by one        if(interp == 1), H.data.xindex = H.data.xindex + 1; end    case 'prevx',        % Decrease current xindex by one        if(interp == 1), H.data.xindex = H.data.xindex - 1; end    case 'nexty', H.data.yindex = H.data.yindex + 1;    case 'prevy', H.data.yindex = H.data.yindex - 1;    case 'ygt',

⌨️ 快捷键说明

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