Home > bioelectromagnetism > crosshair_subplots.m

crosshair_subplots

PURPOSE ^

CROSSHAIR: A gui interface for reading (x,y) values from a plot.

SYNOPSIS ^

function [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);

DESCRIPTION ^

  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;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);
0002 %  CROSSHAIR:  A gui interface for reading (x,y) values from a plot.
0003 %
0004 %  [Xpoint,Ypoint,XYhist] = crosshair_subplots(action);
0005 %
0006 %  A set of mouse driven crosshairs is placed on the current axes,
0007 %  and displays the current (x,y) values of the line plot.  There is an
0008 %  option to provide data specific values or interpolated values.  The
0009 %  resolution of the data specific values depends on both the data
0010 %  resolution and the GUI interface (mainly mouse movement resolution).
0011 %  The interpolated values appear to provide a more continuous function,
0012 %  however they too depend on the GUI interface resolution.  There are
0013 %  no options for extrapolation.
0014 %
0015 %  For multiple traces, plots with the same length(xdata) are
0016 %  tracked. Each mouse click returns Xpoint,Ypoint values and selecting
0017 %  'done' will remove the GUI and restore the mouse buttons to previous
0018 %  values.  Selecting 'exit' will remove the GUI and close the figure.
0019 %
0020 %  In this version (Dec 2002), the crosshairs can track multiple subplots
0021 %  and there are new options to define functions of X/Y and monitor
0022 %  their results.  There is also a new STORE button that creates and
0023 %  updates an XYhist struct in the base workspace, which contains value
0024 %  labels and values.  This version has better controls of X/Y movements,
0025 %  including better interpolation movement options.  This version attempts
0026 %  to respond correctly to keyboard entries, including TAB between subplots,
0027 %  RETURN to 'save', ESC for 'done' and all the arrow keys to move the
0028 %  crosshairs.
0029 %
0030 %  Some further help is given in the tool tips of the GUI.
0031 %
0032 %  Note: crosshair should always update the Xpoint,Ypoint in the base
0033 %  workspace. Here is an example of how to get return values within
0034 %  a script/function after pressing the exit button of crosshair:
0035 %       function [X,Y] = crosshair_returnXY
0036 %        x = [1:10]; y(1,:) = sin(x); y(2,:) = cos(x);
0037 %        figure; plot(x,y); crosshair;
0038 %        uiwait
0039 %        X = evalin('base','Xpoint');
0040 %        Y = evalin('base','Ypoint');
0041 %        return
0042 %  Copy this text to a function .m file and then call it from the
0043 %  base workspace with [X,Y] = crosshair_returnXY
0044 %
0045 %  Useage:  wt=0:0.01:2.5*pi;
0046 %           t=wt;
0047 %           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));
0048 %           subplot(2,1,2), plot(t,sin(2*wt));
0049 %           crosshair_subplots;
0050 %
0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052 
0053 % Copyright (C) 2002  Darren L. Weber
0054 %
0055 % This program is free software; you can redistribute it and/or
0056 % modify it under the terms of the GNU General Public License
0057 % as published by the Free Software Foundation; either version 2
0058 % of the License, or (at your option) any later version.
0059 %
0060 % This program is distributed in the hope that it will be useful,
0061 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0062 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0063 % GNU General Public License for more details.
0064 %
0065 % You should have received a copy of the GNU General Public License
0066 % along with this program; if not, write to the Free Software
0067 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0068 
0069 %  History: 03/96, Richard G. Cobb <cobbr@plk.af.mil>
0070 %           08/01, Darren.Weber@flinders.edu.au
0071 %                  replaced obsolete 'table1' with 'interp1'; fixed bug
0072 %                  with number of 'traces'; rationalized calculations into
0073 %                  a common subfunction for x,y point calc in 'down','up',
0074 %                  & 'move' button functions; added option to turn on/off
0075 %                  interpolation and the exit button; simplified updates
0076 %                  to graphics using global GUI handle structure.
0077 %           11/01, Darren.Weber@flinders.edu.au
0078 %                  added tooltips for several GUI handles
0079 %                  added multiple interpolation methods
0080 %                  added GUI for data matrix indices (given no interpolation)
0081 %                  added option to select trace nearest to mouse click point
0082 %                  reversed order of lines in data matrix to be consistent
0083 %                    with the value returned from the nearest trace subfunction
0084 %                  create crosshair lines after finding all plot lines to
0085 %                    avoid confusing them with the plot lines
0086 %           01/02, Darren.Weber@flinders.edu.au
0087 %                  should now work across multiple plot figures, given
0088 %                    that all gui handles and data are now stored in the
0089 %                    plot figure 'userdata' handle.
0090 %                  added functionality to move smoothly from interpolation
0091 %                    back to the delimited data via the "next/previous"
0092 %                    buttons.
0093 %           06/02, Darren.Weber@flinders.edu.au
0094 %                  learned how to get values back to a script/function with
0095 %                    evalin command and updated help above.
0096 %           12/02, Darren.Weber@flinders.edu.au
0097 %                  added Store uicontrol and associated XYhist variable
0098 %                   updates in base workspace to provide storage of
0099 %                   consecutive XY values (thanks to C.A.Swenne@lumc.nl &
0100 %                   H.van_de_Vooren@lumc.nl for their suggestion/assistance).
0101 %                  added keyboard controls to left/right arrow and return.
0102 %                  added prev/next X interpolation interval.
0103 %                  added handling of subplots in crosshair_subplots version.
0104 %           06/05, suggestion not implemented yet:
0105 % I often use 2 or more vertically arranged sublots with the same x coordinates.
0106 % Would it be possible to adapt  your function to have vertical cursor displayed
0107 % on each sublots with the same x coordinates? Of course y information would be
0108 % written only for one sublot at a time(the selected one)!
0109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0110 
0111 
0112 if ~exist('action','var') 
0113     action = 'init';
0114 elseif isempty(action)
0115     action = 'init';
0116 end
0117 
0118 XHR_HANDLES = get(gcf,'userdata');
0119 
0120 if gca & ~isempty(XHR_HANDLES),
0121     if ~isequal(gca,XHR_HANDLES.axis),
0122         % Ensure we have the right axis data
0123         XHR_HANDLES.axis = gca;
0124         XHR_HANDLES.data = get_data;
0125     end
0126 end
0127 
0128 
0129 % Check for specific keys and assign reasonable actions
0130 if strcmp(action, 'keypress'),
0131     
0132     CC = get(XHR_HANDLES.gui,'CurrentCharacter');
0133     cc = double(CC);
0134     if cc,
0135         switch cc,
0136         case  9, action = 'axes';       % TAB, switch axes, if possible
0137         case 27, action = 'done';       % ESC
0138         case 28, action = 'prevx';      % left
0139         case 29, action = 'nextx';      % right
0140         case 30, action = 'ygt';        % up
0141         case 31, action = 'ylt';        % down
0142         case 13, action = 'store';      % return/enter
0143         otherwise, action = 'up';       % all other keys
0144         end
0145     end
0146 end
0147 
0148 
0149 action = lower(action);
0150 
0151 switch action,
0152 
0153 case 'init',
0154     
0155     % Paint GUI
0156     XHR_HANDLES = INIT;
0157     
0158     % Update and return values
0159     XHR_HANDLES = updateDATA(XHR_HANDLES);
0160     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0161     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0162     %updateXYhistory(Xpoint,Ypoint);
0163     
0164 case 'axes',
0165     
0166     % TAB between axes in subplots of a figure
0167     ax = findobj(gcf,'type','axes');
0168     if length(ax) > 1,
0169         nax = find(ax == gca);
0170         if nax < length(ax),
0171             axes(ax(nax+1));
0172         else
0173             axes(ax(1));
0174         end
0175     end
0176     XHR_HANDLES.axis = gca;
0177     XHR_HANDLES.data = get_data;
0178     XHR_HANDLES = updateGUI(XHR_HANDLES);
0179     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0180     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0181     
0182 % Mouse Click Down
0183 case 'down',
0184     
0185     set(XHR_HANDLES.gui,'WindowButtonMotionFcn','crosshair_subplots(''move'');');
0186     set(XHR_HANDLES.gui,'WindowButtonUpFcn','[Xpoint,Ypoint] = crosshair_subplots(''up'');');
0187     
0188     XHR_HANDLES = updateDATA(XHR_HANDLES);
0189     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0190     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0191     %updateXYhistory(Xpoint,Ypoint);
0192     
0193 % Mouse Drag Motion
0194 case 'move',
0195     
0196     XHR_HANDLES = updateDATA(XHR_HANDLES);
0197     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0198     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0199     %updateXYhistory(Xpoint,Ypoint);
0200     
0201 % Mouse Click Up
0202 case 'up',
0203     
0204     set(XHR_HANDLES.gui,'WindowButtonMotionFcn',' ');
0205     set(XHR_HANDLES.gui,'WindowButtonUpFcn',' ');
0206     
0207     XHR_HANDLES = updateDATA(XHR_HANDLES);
0208     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0209     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0210     %updateXYhistory(Xpoint,Ypoint);
0211     
0212 % Next or Previous X point
0213 case {'nextx','prevx','changex','nexty','prevy','changey','ylt','ygt'}, % Change X/Y
0214     
0215     XHR_HANDLES = moveXY(XHR_HANDLES,action);
0216     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0217     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0218     %updateXYhistory(Xpoint,Ypoint);
0219     
0220 % Store XY values into a history array
0221 case 'store',
0222     
0223     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0224     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0225     updateXYhistory(XHR_HANDLES);
0226     
0227 % Exit crosshairs GUI
0228 case {'done','exit'},
0229     
0230     Xpoint = get(XHR_HANDLES.xvalue,'Value');
0231     Ypoint = get(XHR_HANDLES.yvalue,'Value');
0232     %updateXYhistory(Xpoint,Ypoint);
0233     
0234     handles = fieldnames(XHR_HANDLES);
0235     for i=1:length(handles),
0236         switch handles{i},
0237         case {'axis','datalines','gui'},
0238         otherwise,
0239             h = getfield(XHR_HANDLES,handles{i});
0240             if ishandle(h), delete(h); end
0241         end
0242     end
0243     
0244     if strcmp(action,'exit');
0245         if ishandle(XHR_HANDLES.gui),
0246             close(XHR_HANDLES.gui);
0247         end
0248     else
0249         
0250         lines = findobj(gcf,'tag','XHR_XLINE');
0251         for l = 1:length(lines),
0252             line = lines(l);
0253             if ishandle(line), delete(line); end
0254         end
0255         lines = findobj(gcf,'tag','XHR_YLINE');
0256         for l = 1:length(lines),
0257             line = lines(l);
0258             if ishandle(line), delete(line); end
0259         end
0260         
0261         set(XHR_HANDLES.gui,'WindowButtonUpFcn','');
0262         set(XHR_HANDLES.gui,'WindowButtonMotionFcn','');
0263         set(XHR_HANDLES.gui,'WindowButtonDownFcn',' ');
0264         
0265         refresh(XHR_HANDLES.gui);
0266     end
0267     
0268     clear XHR_HANDLES;
0269     return;
0270     
0271 end
0272 
0273 if ishandle(XHR_HANDLES.axis),
0274     set(XHR_HANDLES.axis,'userdata',XHR_HANDLES.data);
0275 end
0276 
0277 if ishandle(XHR_HANDLES.gui),
0278     set(XHR_HANDLES.gui,'userdata',XHR_HANDLES);
0279     figure(XHR_HANDLES.gui);
0280 end
0281 
0282 return;
0283 
0284 
0285 
0286 
0287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0289 function updateXYhistory(H),
0290     
0291     Ch = get(H.yindex,'Value');
0292     X  = get(H.xvalue,'Value');
0293     Y  = get(H.yvalue,'Value');
0294     fX = get(H.fxvalue,'Value');
0295     fY = get(H.fyvalue,'Value');
0296     
0297     fXeq = get(H.fxeq,'String');
0298     fYeq = get(H.fyeq,'String');
0299     
0300     XY.labels = {'Channel','X','Y',['f(x) = ',fXeq],['f(y) = ',fYeq]};
0301     XY.data   = [Ch,X,Y,fX,fY];
0302     
0303     if evalin('base','exist(''XYhist'',''var'');'),
0304         XYhist = evalin('base','XYhist');
0305         % get the current history set
0306         set = getfield(XYhist,['set',num2str(XYhist.set)]);
0307         if isequal(set.labels,XY.labels),
0308             set.data(end+1,:) = XY.data;
0309             XYhist = setfield(XYhist,['set',num2str(XYhist.set)],set);
0310             assignin('base','XYhist',XYhist);
0311         else
0312             fprintf('\nWarning: creating new set of XYhist in base workspace.\n\n');
0313             XYhist.set = XYhist.set + 1;
0314             XYhist = setfield(XYhist,['set',num2str(XYhist.set)],XY);
0315             assignin('base','XYhist',XYhist);
0316         end
0317     else
0318         XYhist.set = 1;
0319         XYhist.set1 = XY;
0320         assignin('base','XYhist',XYhist);
0321     end
0322     
0323 return
0324 
0325 
0326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0327 function [H] = moveXY(H,move)
0328     
0329     interp  = get(H.interp,'Value');
0330     xinterp = get(H.xinterp,'Value');
0331     
0332     if (xinterp > 0) & (interp > 1),
0333         
0334         % Use incremental interpolation of x values
0335         switch move,
0336         case 'nexty', H.data.yindex = H.data.yindex + 1;
0337         case 'prevy', H.data.yindex = H.data.yindex - 1;
0338         case 'ygt',
0339             ydata = interpYall(H);
0340             [ysort,yi] = sort(ydata);
0341             currYI = find(ysort > H.data.ypoint);
0342             if min(currYI),
0343                 H.data.yindex = yi(min(currYI));
0344             end
0345         case 'ylt',
0346             ydata = interpYall(H);
0347             [ysort,yi] = sort(ydata);
0348             currYI = find(ysort < H.data.ypoint);
0349             if max(currYI),
0350                 H.data.yindex = yi(max(currYI));
0351             end
0352         case 'nextx',
0353             H.data.xpoint = H.data.xpoint + xinterp;
0354         case 'prevx',
0355             H.data.xpoint = H.data.xpoint - xinterp;
0356         end
0357         H = checkdatarange(H);
0358         H = interpY(H);
0359         updateGUI(H);
0360         return
0361     end
0362     
0363     
0364     % No interpolation of x values...
0365     
0366     if (interp > 1)
0367         xdata = H.data.xdata(:,H.data.yindex);
0368         [H.data.xindex] = NearestXYArrayPoint( xdata, H.data.xpoint, move );
0369     end
0370     
0371     switch move,
0372     case 'nextx',
0373         % Increase current xindex by one
0374         if(interp == 1), H.data.xindex = H.data.xindex + 1; end
0375     case 'prevx',
0376         % Decrease current xindex by one
0377         if(interp == 1), H.data.xindex = H.data.xindex - 1; end
0378     case 'nexty', H.data.yindex = H.data.yindex + 1;
0379     case 'prevy', H.data.yindex = H.data.yindex - 1;
0380     case 'ygt',
0381         ydata = H.data.ydata(H.data.xindex,:);
0382         [ysort,yi] = sort(ydata);
0383         currYI = find(ysort == H.data.ypoint);
0384         if currYI < length(yi),
0385             H.data.yindex = yi(currYI+1);
0386         end
0387     case 'ylt',
0388         ydata = H.data.ydata(H.data.xindex,:);
0389         [ysort,yi] = sort(ydata);
0390         currYI = find(ysort == H.data.ypoint);
0391         if currYI > 1,
0392             H.data.yindex = yi(currYI-1);
0393         end
0394     otherwise
0395     end
0396     
0397     H = checkdatarange(H);
0398     
0399     % Get x/y value at new x/y index
0400     H.data.xpoint = H.data.xdata(H.data.xindex,H.data.yindex);
0401     H.data.ypoint = H.data.ydata(H.data.xindex,H.data.yindex);
0402     
0403     set(H.interp,'Value',1);
0404     H = updateGUI(H);
0405     
0406 return
0407 
0408 
0409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0410 function [ H ] = checkdatarange(H),
0411 
0412     % Ensure that x/y index is within data range
0413     s = size(H.data.xdata,1);
0414     if( H.data.xindex < 1 ),
0415         H.data.xindex = 1;
0416     elseif( H.data.xindex >= s ),
0417         H.data.xindex = s;
0418     end
0419     s = size(H.data.ydata,2);
0420     if( H.data.yindex < 1 ),
0421         H.data.yindex = 1;
0422     elseif( H.data.yindex >= s ),
0423         H.data.yindex = s;
0424     end
0425 
0426 return
0427 
0428 
0429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0430 function [ H ] = updateDATA( H )
0431     
0432     % Only update if mouse pointer is in the
0433     % axis limits
0434     set(H.gui,'units','normalized');
0435     axpos = get(H.axis,'position');
0436     figcp = get(H.gui,'Currentpoint');
0437     axlim = axpos(1) + axpos(3);
0438     aylim = axpos(2) + axpos(4);
0439     if or(figcp(1) > (axlim+.01), figcp(1) < (axpos(1)-.01)),
0440         return;
0441     elseif or(figcp(2) > (aylim+.01), figcp(2) < (axpos(2)-.01)),
0442         return;
0443     end
0444     
0445     CurrentPoint  = get(H.axis,'Currentpoint');
0446     H.data.xpoint = CurrentPoint(1,1);
0447     H.data.ypoint = CurrentPoint(1,2);
0448     
0449     if get(H.traceNearest,'Value'),
0450         
0451         % Get new yindex for nearest trace
0452         [ H.data.xpoint, ...
0453           H.data.xindex, ...
0454           H.data.ypoint, ...
0455           H.data.yindex ] = NearestXYMatrixPoint( H.data.xdata,...
0456                                                   H.data.ydata,...
0457                                                   H.data.xpoint,...
0458                                                   H.data.ypoint);
0459     end
0460     
0461     CurrentPoint  = get(H.axis,'Currentpoint');
0462     H.data.xpoint = CurrentPoint(1,1);
0463     H.data.ypoint = CurrentPoint(1,2);
0464     
0465     H = interpY(H);
0466     H = updateGUI(H);
0467 
0468 return
0469 
0470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0471 function [ H ] = updateGUI( H )
0472 
0473     InterpMethod = get(H.interp,'Value');
0474     if (InterpMethod > 1)
0475         % There is no specific matrix x-index for
0476         % an interpolated point, but the nearest xindex
0477         % is always returned from the interp function below
0478         % so that next/prev move function works correctly
0479         set(H.xindex,'String','interp');
0480     else
0481         set(H.xindex,'String',num2str(H.data.xindex));
0482     end
0483     set(H.xindex,'Value',H.data.xindex);
0484     
0485     tracestr = sprintf('%d',H.data.yindex);
0486     set(H.yindex,'String',tracestr,'Value',uint16(H.data.yindex));
0487     %set(H.trace,'Value',uint16(H.data.yindex));
0488     
0489     % Create the crosshair lines on the figure, crossing at the x,y point
0490     x_rng  = get(H.axis,'Xlim');
0491     y_rng  = get(H.axis,'Ylim');
0492     set(H.data.xline,'Xdata',[H.data.xpoint H.data.xpoint],'Ydata',y_rng);
0493     set(H.data.yline,'Ydata',[H.data.ypoint H.data.ypoint],'Xdata',x_rng);
0494     
0495     % Update the x,y values displayed for the x,y point
0496     xstring = sprintf('%g',H.data.xpoint);
0497     ystring = sprintf('%g',H.data.ypoint);
0498     set(H.xvalue,'String',xstring,'Value',H.data.xpoint);
0499     set(H.yvalue,'String',ystring,'Value',H.data.ypoint);
0500     
0501     % Calculate the f(x) function
0502     fyeq = get(H.fyeq,'string');
0503     fyval = eval(strrep(fyeq,'y',ystring));
0504     fystr = sprintf('%g',fyval);
0505     set(H.fyvalue,'String',fystr,'Value',fyval);
0506     
0507     % Calculate the f(y) function
0508     fxeq = get(H.fxeq,'string');
0509     fxval = eval(strrep(fxeq,'x',xstring));
0510     fxstr = sprintf('%g',fxval);
0511     set(H.fxvalue,'String',fxstr,'Value',fxval);
0512     
0513 return
0514 
0515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0516 function [ H ] = interpY( H )
0517     
0518     % In this function, xdata & ydata are arrays, not matrices
0519     xdata = H.data.xdata(:,H.data.yindex);
0520     ydata = H.data.ydata(:,H.data.yindex);
0521     
0522     if      H.data.xpoint >= max(xdata)                
0523             H.data.xpoint  = max(xdata);
0524             H.data.xindex  = find(xdata == max(xdata));
0525             H.data.ypoint  = ydata(H.data.xindex);
0526             return;
0527     elseif  H.data.xpoint <= min(xdata)
0528             H.data.xpoint  = min(xdata);
0529             H.data.xindex  = find(xdata == min(xdata));
0530             H.data.ypoint  = ydata(H.data.xindex);
0531             return;
0532     end
0533     
0534     % 'none|nearest|linear|spline|cubic'
0535     interp = get(H.interp,'Value');
0536     
0537     switch interp
0538     case 1
0539         % Given that xdata & ydata are the same length arrays,
0540         % we can find the ypoint given the nearest xpoint.
0541         [H.data.xindex, H.data.xpoint] = NearestXYArrayPoint( xdata, H.data.xpoint );
0542         H.data.ypoint = ydata(H.data.xindex);
0543     case 2
0544         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'nearest' );
0545     case 3
0546         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'linear' );
0547     case 4
0548         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'spline' );
0549     case 5
0550         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'cubic' );
0551     otherwise
0552         %use default (linear in matlabR12)
0553         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint );
0554     end
0555 
0556 return
0557 
0558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0559 function [ Yall ] = interpYall( H )
0560     
0561     xdata = H.data.xdata(:,H.data.yindex);
0562     Yall  = H.data.ydata;
0563     
0564     if      H.data.xpoint >= max(xdata),
0565             H.data.xpoint  = max(xdata);
0566             H.data.xindex  = find(xdata == max(xdata));
0567             Yall = ydata(:,H.data.xindex);
0568             return;
0569     elseif  H.data.xpoint <= min(xdata),
0570             H.data.xpoint  = min(xdata);
0571             H.data.xindex  = find(xdata == min(xdata));
0572             Yall = ydata(:,H.data.xindex);
0573             return;
0574     end
0575     
0576     % 'none|nearest|linear|spline|cubic'
0577     interp = get(H.interp,'Value');
0578     
0579     switch interp,
0580     case 1
0581         % do nothing in this case
0582     case 2
0583         Yall = interp1( xdata, Yall, H.data.xpoint, 'nearest' );
0584     case 3
0585         Yall = interp1( xdata, Yall, H.data.xpoint, 'linear' );
0586     case 4
0587         Yall = interp1( xdata, Yall, H.data.xpoint, 'spline' );
0588     case 5
0589         Yall = interp1( xdata, Yall, H.data.xpoint, 'cubic' );
0590     otherwise
0591         %use default (linear in matlabR12)
0592         Yall = interp1( xdata, Yall, H.data.xpoint );
0593     end
0594 
0595 return
0596 
0597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0598 function [ index, point ] = NearestXYArrayPoint( data_array, point, type )
0599     
0600     if ~exist('type','var') type = ''; end
0601 
0602     % In this function, input data_array is an array, not a matrix.
0603     % This function returns the data point in the array
0604     % that has the closest value to the value given (point).  In
0605     % the context of 'crosshair' the point is a mouse position.
0606     
0607     if      point >= max(data_array)
0608             point  = max(data_array);
0609             index  = find(data_array == point);
0610             return;
0611     elseif  point <= min(data_array)
0612             point  = min(data_array);
0613             index  = find(data_array == point);
0614             return;
0615     end
0616     
0617     data_sorted = sort(data_array);
0618     
0619     greater = find(data_sorted > point);
0620     greater_index = greater(1);
0621     
0622     lesser = find(data_sorted < point);
0623     lesser_index = lesser(length(lesser));
0624     
0625     greater_dif = data_sorted(greater_index) - point;
0626     lesser_dif  = point - data_sorted(lesser_index);
0627     
0628     if strcmp(type,'nextx'),
0629         index = greater_index;
0630     elseif strcmp(type,'prevx'),
0631         index = lesser_index;
0632     else
0633         if (greater_dif < lesser_dif)
0634             index = find(data_array == data_sorted(greater_index));
0635         else
0636             index = find(data_array == data_sorted(lesser_index));
0637         end
0638     end
0639     point = data_array(index);
0640     
0641 return
0642 
0643 
0644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0645 function [ xpoint, xindex, ypoint, yindex ] = NearestXYMatrixPoint( Xdata, Ydata, xpoint, ypoint )
0646 
0647     % In this function, Xdata & Ydata are matrices of the same dimensions.
0648     % This function attempts to find the nearest values in Xdata & Ydata
0649     % to the mouse position (xpoint, ypoint).
0650     
0651     % It is assumed that Xdata has identical columns, so we only really
0652     % need the first column to find the nearest value to xpoint.
0653     
0654     [ xindex, xpoint ] = NearestXYArrayPoint( Xdata(:,1), xpoint );
0655     
0656     % Now, given the xpoint, we can select just that row of the
0657     % Ydata matrix corresponding to the xpoint.
0658     ydata = Ydata(xindex,:);
0659     
0660     % The ydata array is searched in same manner as the xdata
0661     % array for the nearest value.
0662     [ yindex, ypoint ] = NearestXYArrayPoint( ydata, ypoint );
0663     
0664 return
0665 
0666 
0667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0668 function [ data ] = get_data,
0669 
0670     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0671     % Get Line Data from Current Axes
0672     
0673     if gca,
0674         
0675         % see if we have stored any data in userdata already
0676         data = get(gca,'userdata');
0677         
0678         if isfield(data,'lineobj'),
0679             if data.lineobj,
0680                 return;
0681             end
0682         end
0683         
0684         data.ylim = get(gca,'ylim');
0685         
0686         % Get all the line objects from the current axis
0687         data.lineobj = findobj(gca,'Type','line');
0688         
0689         if data.lineobj,
0690             
0691             data.lines = length(data.lineobj);
0692             data.xdata = [];
0693             data.ydata = [];
0694             data.xpoint = [];
0695             data.ypoint = [];
0696             data.xindex = 1;
0697             data.yindex = 1;
0698             for i = data.lines:-1:1,
0699                 
0700                 % put line data into a columns of data
0701                 data.xdata(:,i) = get(data.lineobj(i),'XData').';
0702                 data.ydata(:,i) = get(data.lineobj(i),'YData').';
0703             end
0704             
0705             % Set X,Y cross hair lines
0706             % Do this after finding all the line axis children
0707             % to avoid confusing these lines with those of the
0708             % plot itself (counted above).
0709             x_rng = get(gca,'Xlim');
0710             y_rng = get(gca,'Ylim');
0711             data.xline = line(x_rng,[y_rng(1) y_rng(1)]);
0712             data.yline = line(x_rng,[y_rng(1) y_rng(1)]);
0713             set(data.xline,'Color','r','EraseMode','xor','tag','XHR_XLINE');
0714             set(data.yline,'Color','r','EraseMode','xor','tag','XHR_YLINE');
0715             
0716             set(gca,'userdata',data);
0717             
0718         else
0719             fprintf('No lines in current axes\n');
0720         end
0721         
0722     end
0723     
0724 return
0725 
0726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0727 function [H] = INIT
0728 
0729     H.gui  = gcf; % Get current figure handles
0730     H.axis = gca; % Get current axis handles
0731     
0732     H.data = get_data;
0733     
0734     % store current button fcn
0735     H.button = get(H.gui,'WindowButtonDownFcn');
0736     % set XHR button down fcn
0737     set(H.gui,'WindowButtonDownFcn','crosshair_subplots(''down'');');
0738     set(H.gui,'KeyPressFcn','crosshair_subplots(''keypress'');');
0739     
0740     % Match background figure colour
0741     bgcolor = get(H.gui,'Color');
0742     % Try to adapt the foreground colour a little
0743     black = find(bgcolor <= .6);
0744     fgcolor = [0 0 0]; %black text
0745     if length(black)>2, fgcolor = [1 1 1]; end
0746     
0747     
0748     Font.FontName   = 'Helvetica';
0749     Font.FontUnits  = 'Pixels';
0750     Font.FontSize   = 10;
0751     Font.FontWeight = 'normal';
0752     Font.FontAngle  = 'normal';
0753     
0754     
0755     if findobj(gcf,'tag','XHR_YFLIP'),
0756         H.yflip = findobj(gcf,'tag','XHR_YFLIP');
0757     else
0758         H.yflip = uicontrol(H.gui,'tag','XHR_YFLIP','Style','pushbutton',...
0759             'Units','Normalized',Font,...
0760             'Position',[.00 .95 .08 .05],...
0761             'TooltipString','Flip Y Axis', ...
0762             'String','Flip',...
0763             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0764             'ydir = get(XHR.axis,''YDir'');',...
0765             'if isequal(ydir,''normal''),',...
0766             '   set(XHR.axis,''YDir'',''reverse'');',...
0767             'else,',...
0768             '   set(XHR.axis,''YDir'',''normal'');',...
0769             'end;',...
0770             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0771     end
0772     
0773     if findobj(gcf,'tag','XHR_YRESET'),
0774         H.yreset = findobj(gcf,'tag','XHR_YRESET');
0775     else
0776         H.yreset = uicontrol(H.gui,'tag','XHR_YRESET','Style','pushbutton',...
0777             'Units','Normalized',Font,...
0778             'Position',[.00 .90 .08 .05],...
0779             'TooltipString','Reset Axis Limits', ...
0780             'String','Reset',...
0781             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0782             'XHR.data.ylim = get(XHR.axis,''ylim'');',...
0783             'set(XHR.ymin,''string'',sprintf(''%g'',XHR.data.ylim(1)));',...
0784             'set(XHR.ymax,''string'',sprintf(''%g'',XHR.data.ylim(2)));',...
0785             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0786     end
0787     
0788     if findobj(gcf,'tag','XHR_YMIN'),
0789         H.ymin = findobj(gcf,'tag','XHR_YMIN');
0790     else
0791         H.ymin = uicontrol(H.gui,'tag','XHR_YMIN','Style','edit',...
0792             'Units','Normalized',Font,...
0793             'Position',[.00 .85 .08 .05],...
0794             'HorizontalAlign','left',...
0795             'TooltipString','Set Y min', ...
0796             'String',sprintf('%g',H.data.ylim(1)),...
0797             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0798             'ymin = str2num(get(XHR.ymin,''string''));',...
0799             'XHR.data.ylim(1) = ymin;',...
0800             'set(XHR.axis,''ylim'',XHR.data.ylim);',...
0801             'set(XHR.ymin,''string'',sprintf(''%g'',XHR.data.ylim(1)));',...
0802             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR ymin;'));
0803     end
0804     
0805     if findobj(gcf,'tag','XHR_YMAX'),
0806         H.ymax = findobj(gcf,'tag','XHR_YMAX');
0807     else
0808         H.ymax = uicontrol(H.gui,'tag','XHR_YMAX','Style','edit',...
0809             'Units','Normalized',Font,...
0810             'Position',[.00 .80 .08 .05],...
0811             'HorizontalAlign','left',...
0812             'TooltipString','Set Y max', ...
0813             'String',sprintf('%g',H.data.ylim(2)),...
0814             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0815             'ymax = str2num(get(XHR.ymax,''string''));',...
0816             'XHR.data.ylim(2) = ymax;',...
0817             'set(XHR.axis,''ylim'',XHR.data.ylim);',...
0818             'set(XHR.ymax,''string'',sprintf(''%g'',XHR.data.ylim(2)));',...
0819             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR ymax;'));
0820     end
0821     
0822     if findobj(gcf,'tag','XHR_GRID'),
0823         H.grid = findobj(gcf,'tag','XHR_GRID');
0824     else
0825         H.grid = uicontrol(H.gui,'tag','XHR_GRID','Style','checkbox',...
0826             'Units','Normalized',Font,...
0827             'Position',[.00 .75 .08 .05],...
0828             'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
0829             'TooltipString','Toggle plot grid on/off.', ...
0830             'String','grid',...
0831             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0832             'grid(XHR.axis);',...
0833             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0834     end
0835     
0836     if findobj(gcf,'tag','XHR_XVALUE'),
0837         H.xvalue = findobj(gcf,'tag','XHR_XVALUE');
0838     else
0839         H.xvalue = uicontrol(H.gui,'tag','XHR_XVALUE','Style','edit',...
0840             'Units','Normalized',Font,...
0841             'Position',[.13 .95 .15 .05],...
0842             'BackGroundColor',[ 0 .9 0],'ForeGroundColor',[ 0 0 0],...
0843             'TooltipString','X value (Read Only)',...
0844             'String',' ');
0845     end
0846     
0847     if findobj(gcf,'tag','XHR_YVALUE'),
0848         H.yvalue = findobj(gcf,'tag','XHR_YVALUE');
0849     else
0850         H.yvalue = uicontrol(H.gui,'tag','XHR_YVALUE','Style','edit',...
0851             'Units','Normalized',Font,...
0852             'Position',[.28 .95 .15 .05],...
0853             'BackGroundColor',[ 0 0 .9],'ForeGroundColor',[ 1 1 1],...
0854             'TooltipString','Y value (Read Only)',...
0855             'String',' ');
0856     end
0857     
0858     if findobj(gcf,'tag','XHR_FXEQ'),
0859         H.fxeq = findobj(gcf,'tag','XHR_FXEQ');
0860     else
0861         H.fxeq = uicontrol(H.gui,'tag','XHR_FXEQ','Style','edit',...
0862             'Units','Normalized',...
0863             'Position',[.45 .95 .10 .05],...
0864             'TooltipString','Define f(x) equation here',...
0865             'BackGroundColor',[ 0 .9 0],...
0866             'ForeGroundColor',[ 0 0 0],'String','x');
0867     end
0868     
0869     if findobj(gcf,'tag','XHR_FXVALUE'),
0870         H.fxvalue = findobj(gcf,'tag','XHR_FXVALUE');
0871     else
0872         H.fxvalue = uicontrol(H.gui,'tag','XHR_FXVALUE','Style','edit',...
0873             'Units','Normalized',...
0874             'Position',[.55 .95 .15 .05],...
0875             'TooltipString','f(x) result',...
0876             'BackGroundColor',[ 0 .9 0],...
0877             'ForeGroundColor',[ 0 0 0],'String',' ');
0878     end
0879     
0880     if findobj(gcf,'tag','XHR_FYEQ'),
0881         H.fyeq = findobj(gcf,'tag','XHR_FYEQ');
0882     else
0883         H.fyeq = uicontrol(H.gui,'tag','XHR_FYEQ','Style','edit',...
0884             'Units','Normalized',...
0885             'Position',[.70 .95 .10 .05],...
0886             'TooltipString','Define f(y) equation here',...
0887             'BackGroundColor',[ 0 0 .9],...
0888             'ForeGroundColor',[ 1 1 1],'String','y');
0889     end
0890     
0891     if findobj(gcf,'tag','XHR_FYVALUE'),
0892         H.fyvalue = findobj(gcf,'tag','XHR_FYVALUE');
0893     else
0894         H.fyvalue = uicontrol(H.gui,'tag','XHR_FYVALUE','Style','edit',...
0895             'Units','Normalized',...
0896             'Position',[.80 .95 .15 .05],...
0897             'TooltipString','f(y) result',...
0898             'BackGroundColor',[ 0 0 .9],...
0899             'ForeGroundColor',[ 1 1 1],'String',' ');
0900     end
0901     
0902     if findobj(gcf,'tag','XHR_YINDEX'),
0903         H.yindex = findobj(gcf,'tag','XHR_YINDEX');
0904     else
0905         H.yindex = uicontrol(H.gui,'tag','XHR_YINDEX','Style','edit',...
0906             'Units','Normalized',Font,...
0907             'Position',[.92 .87 .08 .05],...
0908             'BackGroundColor',[ 0 0 .9],'ForeGroundColor',[ 1 1 1],...
0909             'TooltipString','Enter Y index into plot data matrix.  Same as trace number.',...
0910             'String','1','Value',1,...
0911             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0912             'yi = str2num(get(XHR.yindex,''String''));',...
0913             'XHR.data.yindex = yi;',...
0914             'set(XHR.gui,''userdata'',XHR); clear XHR yi; ',...
0915             '[Xpoint,Ypoint] = crosshair_subplots(''changey'');'));
0916     end
0917     
0918     if findobj(gcf,'tag','XHR_YPREV'),
0919         H.yprev = findobj(gcf,'tag','XHR_YPREV');
0920     else
0921         H.yprev = uicontrol(H.gui,'tag','XHR_YPREV','Style','Push',...
0922             'Units','Normalized',Font,...
0923             'Position',[.92 .82 .04 .05],...
0924             'String','<',...
0925             'TooltipString','Goto Previous Y Index (channel).',...
0926             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''prevy'');');
0927     end
0928     
0929     if findobj(gcf,'tag','XHR_YNEXT'),
0930         H.ynext = findobj(gcf,'tag','XHR_YNEXT');
0931     else
0932         H.ynext = uicontrol(H.gui,'tag','XHR_YNEXT','Style','Push',...
0933             'Units','Normalized',Font,...
0934             'Position',[.96 .82 .04 .05],...
0935             'String','>',...
0936             'TooltipString','Goto Next Y Index (channel).',...
0937             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''nexty'');');
0938     end
0939     
0940     if findobj(gcf,'tag','XHR_YLT'),
0941         H.yLT = findobj(gcf,'tag','XHR_YLT');
0942     else
0943         H.yLT = uicontrol(H.gui,'tag','XHR_YLT','Style','Push',...
0944             'Units','Normalized',Font,...
0945             'Position',[.92 .77 .04 .05],...
0946             'String','LT',...
0947             'TooltipString','Goto next Y Less Than current Y.',...
0948             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''yLT'');');
0949     end
0950     
0951     if findobj(gcf,'tag','XHR_YGT'),
0952         H.yGT = findobj(gcf,'tag','XHR_YGT');
0953     else
0954         H.yGT = uicontrol(H.gui,'tag','XHR_YGT','Style','Push',...
0955             'Units','Normalized',Font,...
0956             'Position',[.96 .77 .04 .05],...
0957             'String','GT',...
0958             'TooltipString','Goto next Y Greater Than current Y.',...
0959             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''yGT'');');
0960     end
0961     
0962     if findobj(gcf,'tag','XHR_XINDEX'),
0963         H.xindex = findobj(gcf,'tag','XHR_XINDEX');
0964     else
0965         H.xindex = uicontrol(H.gui,'tag','XHR_XINDEX','Style','edit',...
0966             'Units','Normalized',Font,...
0967             'Position',[.92 .70 .08 .05],...
0968             'BackGroundColor',[ 0 .9 0],'ForeGroundColor',[ 0 0 0],...
0969             'TooltipString','Enter X index into plot data matrix.  Only available for interpolation = ''none''.',...
0970             'String','1','Value',1,...
0971             'Callback',strcat('XHR = get(gcf,''userdata'');',...
0972             'xi = str2num(get(XHR.xindex,''String''));',...
0973             'XHR.data.xindex = xi;',...
0974             'set(XHR.xinterp,''value'',0); ',...
0975             'set(XHR.xinterp,''string'',''0''); ',...
0976             'set(XHR.interp, ''value'',1); ',...
0977             'set(XHR.gui,''userdata'',XHR); clear XHR; ',...
0978             '[Xpoint,Ypoint] = crosshair_subplots(''changex'');'));
0979     end
0980     
0981     if findobj(gcf,'tag','XHR_XPREV'),
0982         H.xprev = findobj(gcf,'tag','XHR_XPREV');
0983     else
0984         H.xprev = uicontrol(H.gui,'tag','XHR_XPREV','Style','Push',...
0985             'Units','Normalized',Font,...
0986             'Position',[.92 .65 .04 .05],...
0987             'String','<',...
0988             'TooltipString','Goto Previous X Index (no interpolation).',...
0989             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''prevx'');');
0990     end
0991     
0992     if findobj(gcf,'tag','XHR_XNEXT'),
0993         H.xnext = findobj(gcf,'tag','XHR_XNEXT');
0994     else
0995         H.xnext = uicontrol(H.gui,'tag','XHR_XNEXT','Style','Push',...
0996             'Units','Normalized',Font,...
0997             'Position',[.96 .65 .04 .05],...
0998             'String','>',...
0999             'TooltipString','Goto Next X Index (no interpolation).',...
1000             'CallBack','[Xpoint,Ypoint] = crosshair_subplots(''nextx'');');
1001     end
1002     
1003     if findobj(gcf,'tag','XHR_XINTERP'),
1004         H.xinterp = findobj(gcf,'tag','XHR_XINTERP');
1005     else
1006         H.xinterp = uicontrol(H.gui,'tag','XHR_XINTERP','Style','Edit',...
1007             'Units','Normalized',...
1008             'Position',[.92 .60 .08 .05],...
1009             'String','0','Value',0,...
1010             'TooltipString','Interpolation X increment (zero = nearest X).',...
1011             'Callback',strcat('XHR = get(gcf,''userdata''); ',...
1012             'xint = str2num(get(XHR.xinterp,''string'')); ',...
1013             'set(XHR.xinterp,''value'',xint); ',...
1014             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; '));
1015     end
1016     
1017     if findobj(gcf,'tag','XHR_INTERP'),
1018         H.interp = findobj(gcf,'tag','XHR_INTERP');
1019     else
1020         interpstr = 'none|nearest|linear|spline|cubic';
1021         H.interp = uicontrol(H.gui,'tag','XHR_INTERP','Style','popup',...
1022             'Units','Normalized',Font,...
1023             'Position',[.92 .55 .08 .05],...
1024             'TooltipString','INTERP1 methods (none = raw values).', ...
1025             'String',interpstr,...
1026             'Callback',strcat('XHR = get(gcf,''userdata'');',...
1027             'xint = get(XHR.xinterp,''Value''); ',...
1028             'if xint == 0, ',...
1029             '   xint = 0.5; ',...
1030             '   set(XHR.xinterp,''value'',xint); ',...
1031             '   set(XHR.xinterp,''string'',num2str(xint)); ',...
1032             '   set(XHR.xindex, ''string'',''interp''); ',...
1033             'end; ',...
1034             'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; '));
1035     end
1036     
1037     if findobj(gcf,'tag','XHR_STORE'),
1038         H.store = findobj(gcf,'tag','XHR_STORE');
1039     else
1040         H.store = uicontrol(H.gui,'tag','XHR_STORE','Style','Push',...
1041             'Units','Normalized',...
1042             'Position',[.92 .40 .08 .05],...
1043             'String','Store',...
1044             'TooltipString','Store current Channel & XY values into base XYhist array.', ...
1045             'CallBack','crosshair_subplots(''store'');');
1046     end
1047     
1048     if findobj(gcf,'tag','XHR_DONE'),
1049         H.done = findobj(gcf,'tag','XHR_DONE');
1050     else
1051         H.done = uicontrol(H.gui,'tag','XHR_DONE','Style','Push',...
1052             'Units','Normalized',...
1053             'Position',[.80 .00 .10 .05],...
1054             'BackgroundColor',[.8 .5 0],...
1055             'ForegroundColor',[1 1 1],...
1056             'FontWeight','bold',...
1057             'String','Done',...
1058             'TooltipString','Close crosshair', ...
1059             'CallBack','crosshair_subplots(''done'');');
1060     end
1061     
1062     if findobj(gcf,'tag','XHR_EXIT'),
1063         H.exit = findobj(gcf,'tag','XHR_EXIT');
1064     else
1065         H.exit = uicontrol(H.gui,'tag','XHR_EXIT','Style','Push',...
1066             'Units','Normalized',...
1067             'Position',[.90 .00 .10 .05],...
1068             'BackgroundColor',[.8 0 0],...
1069             'ForegroundColor',[1 1 1],...
1070             'FontWeight','bold',...
1071             'String','Exit',...
1072             'TooltipString','Close crosshair and Figure', ...
1073             'CallBack','crosshair_subplots(''exit'');');
1074     end
1075     
1076     if findobj(gcf,'tag','XHR_TRACENEAREST'),
1077         H.traceNearest = findobj(gcf,'tag','XHR_TRACENEAREST');
1078     else
1079         H.traceNearest = uicontrol(H.gui,'tag','XHR_TRACENEAREST','Style','checkbox',...
1080             'Units','Normalized',...
1081             'Position',[.60 .00 .19 .05],...
1082             'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1083             'String','Nearest Trace','Value',1,...
1084             'TooltipString','Trace nearest to mouse click; switch off to keep trace constant.');
1085     end
1086     
1087 %     % Switch off||on Trace Selection GUI
1088 %     Vis = 'Off';
1089 %     if H.data.lines > 1,
1090 %         Vis = 'On';
1091 %     elseif H.data.lines == 0
1092 %         error('No lines found in the current axes (gca)\n');
1093 %     end
1094 %
1095 %     % 'traces' string variable must be in ascending order
1096 %     traces  = '';
1097 %     i = 1;
1098 %     while i <= lines;
1099 %         if i < lines
1100 %             tracelabel = sprintf('Column %4d|',i);
1101 %         else
1102 %             tracelabel = sprintf('Column %4d',i);
1103 %         end
1104 %         traces = strcat(traces,tracelabel);
1105 %         i = i + 1;
1106 %     end
1107 %
1108 %     % If more than one line, provide GUI for line selection
1109 %
1110 %
1111 %     if findobj(gcf,'tag','XHR_TRACESWITCH'),
1112 %         H.trace = findobj(gcf,'tag','XHR_TRACESWITCH');
1113 %         set(H.trace,'String',traces);
1114 %     else
1115 %         H.trace = uicontrol(H.gui,'tag','XHR_TRACESWITCH','Style','Popup',...
1116 %             'Units','Normalized',...
1117 %             'Position',[.15 .00 .20 .05],...
1118 %             'BackGroundColor','w','String',traces,...
1119 %             'TooltipString','Select trace to follow with crosshairs.',...
1120 %             'Visible',Vis,...
1121 %             'CallBack','crosshair_subplots(''up'');');
1122 %     end
1123     
1124     
1125     set(H.axis,'userdata',H.data);
1126     set(H.gui,'userdata',H);
1127     
1128 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003