No BSD License  

Highlights from
MagnetGInput

5.0

5.0 | 4 ratings Rate this file 12 Downloads (last 30 days) File Size: 2 KB File ID: #3265
image thumbnail

MagnetGInput

by Michael Robbins

 

15 Apr 2003 (Updated 18 Apr 2003)

Returns the position of the closest datapoint to your mouse click.

| Watch this File

File Information
Description

MAGNETGINPUT(h,N,test)
  Given the handle of the plot, h, MAGNETGINPUT will either
  return the position clicked (upon right button press) or
  the location of the datapoint closest to the position
  clicked (upon left button press)
 
  If N is provided, MagnetGInput will allow N button clicks
 
  The closest datapoint is determined by minimizing the
  distance which is weighted by the scale of the figure,
  such that if your figure is [0:1:0:1000], the distance
  is
 
     sqrt(((X-x)./1).^2+((Y-y)./1000).^2);
 
  It returns the abscissa and ordinate of the point clicked
  or datapoint closest to that point as well as the distance
  from the returned position to the click.
 
  If TEST is set true, MAGENETGINPUT will draw a red line
  from the click to the closest datapoint and a red circle
  using the click as the origin and the distance to the
  closest datapoint as a radius
 
  USAGE:
 
    y=sin([.1:.1:10])+rand(1,100).*0.1;
    h=plot([1:100],y,'-');
    [xin,yin,rin]=MagnetGInput(h);
    % click on your plot with the LEFT mouse button
    line(xin+[0 10],yin+[0 .5],'color','r');
    text(xin+10,yin+.5,{'This datapoint','was the closest to','your mouse click'},'color','r');
    hold on;plot(xin,yin,'ro');
    
  IT'S NOT FANCY BUT IT WORKS.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
20 Jun 2003 Larry Velasco

Excelent...

19 Mar 2004 Chris Paterson

Nice one Mike, keep up the good work...

10 Sep 2004 Rebecca Maletsky

just what I was looking for...

16 Feb 2007 John Franz

Awesome little script. Well documented, and easy to modify to pick a point from plots with multiple lines. Thanks!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data exploration Michael Robbins 22 Oct 2008 06:59:51
ginput Michael Robbins 22 Oct 2008 06:59:51
magnet Michael Robbins 22 Oct 2008 06:59:51
snap Michael Robbins 22 Oct 2008 06:59:51
graph Michael Robbins 22 Oct 2008 06:59:51
graphical Michael Robbins 22 Oct 2008 06:59:51
plot Michael Robbins 22 Oct 2008 06:59:51
input Michael Robbins 22 Oct 2008 06:59:51
snap Jaap 03 Jan 2012 05:43:58

Contact us at files@mathworks.com