No BSD License  

Highlights from
plot crosshairs

4.46154

4.5 | 13 ratings Rate this file 8 Downloads (last 30 days) File Size: 59.88 KB File ID: #1038
image thumbnail

plot crosshairs

by Darren Weber

 

08 Nov 2001 (Updated 24 Dec 2002)

A gui interface for reading (x,y) values from line plot(s).

| Watch this File

File Information
Description

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). To overcome this limitation, there are next & previous buttons that move the x dimension of the crosshairs one point at a time. Interpolated values provide a more continuous function, however they too depend on the GUI interface resolution. There are currently no options for extrapolation. Further help is given in tool tips of the GUI.

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.

The function now works across multiple plot figures (01/2002).
 
Useage: x = [1:10]; y(1,:) = sin(x); y(2,:) = cos(x);
figure; plot(x,y); crosshair

Note: crosshair always updates 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

Acknowledgements
This submission has inspired the following:
Antenna Design Wizards
MATLAB release MATLAB 6.0 (R12)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (14)
09 Nov 2001 Jim Smith

You can't use the arrow keys to "fine tune" the cursor, but you can use the "Prev X" and "Next X" buttons. Useful tool.

03 Jul 2002 John Lipp

Great.. this overcomes one of the biggest inadequacies of the matlab plotting capabilities - that of not having a cursor readout built in. Only things making it short of scoring 5 are: that it does not allow for fine adjustment with cursor keys; and that the crosshairs appear behind the buttons on the GUI, making them hard to see. Still a very useful and useable tool, giving functionality that should really be standard in MATLAB.

02 Oct 2002 Antoni Batalla

Maybe I use it wrong, but I cant get the values interpolated, the way you do it with ginput.
On the other side, wouldnt it be nice if 'ginput' just showed the x-y coordinates continually as you move your crosshair ? that would be great !

20 Dec 2002 John Lipp

OK, it is my second go at rating, but as from the upgrade dated 2002-12-18 I want to give it full marks. A great tool with all the funtionality I can think I'll ever want from it. The ability to slide the crosshairs around the interpolated curve is just great.... and it can be done without having to touch the mouse.

28 Jan 2003 Richard Hutchins

Wow!! This is just what I have been looking for! This is the best file that I have used from the exchange yet!

29 Jan 2003 C.K. Gan

This is a great function that I am looking for, it allows using the plot and subplot matlab function as well.
It would be nice if a uicontrol slider is inserted just below the graph, so that when there is long window of data plot, we can slide the window and have better view of the plot.
Great Job Darren.

03 Feb 2003 Cees A. Swenne

Our quest for a Matlab crosshair function led us to the one developed by Darren Weber. When we needed multiple mouseclicks during one crosshair 'session', Darren Weber was so kind to modify it. In my view this crosshair function (there are not that many...) is now a super-practical universal interactive signal analysis tool.

13 Mar 2003 thomas toth

quite nice. having problems though if i have multiple plots in the same window (used hold on).

01 Apr 2003 Matthias Wetzel  
05 Jun 2003 Martina Balic

it is nice, and usefull. i was surprised that matlab does not have something like this built in. still i have problem using it with multilple plots (using subplot). any suggestion?

05 Jun 2003 Martina B

works with subplot !!! previouslly it was my mistake. i will be using it a lot. thanks!

18 Mar 2004 Alex Munoz

It will be much better with extrapolation options

09 Feb 2005 Debarag Banerjee  
11 Apr 2007 petru balan  
Please login to add a comment or rating.
Updates
11 Nov 2001

Minor fix just to remove next & prev GUI buttons once 'done'.

09 Jan 2002

The GUI now works across multiple figures

24 Jun 2002

FAQ about how to get values back to a calling script or function. Identified solution and updated help section with example.

13 Dec 2002

This revision incorporates suggestions to provide options for saving consecutive points (now available in XYhist in base workspace). It also provides options to define f(x) and f(y), the results of which are display and saved into XYhist.

16 Dec 2002

Save consecutive points (into XYhist in base workspace). Define f(x) and f(y), also saved into XYhist. Interpret keypress events.

19 Dec 2002

Better interpolation handling and more Y axis and movement controls.

24 Dec 2002

Additional version to handle subplots of a figure, crosshair_subplots.m

Tag Activity for this File
Tag Applied By Date/Time
data exploration Darren Weber 22 Oct 2008 06:39:10
line Darren Weber 22 Oct 2008 06:39:10
plot Darren Weber 22 Oct 2008 06:39:10
crosshairs Darren Weber 22 Oct 2008 06:39:10
mouseinteraction Darren Weber 22 Oct 2008 06:39:10

Contact us at files@mathworks.com