tags:

views:

114

answers:

1

I wrote a small MATLAB program with a gui. Inside the gui I have, among other things, a plot in which the user should be able to select two points. For this I use the function ginput, which creates a crosshair for selection. Unfortunatley the crosshair extends the whole window and is not restricted to the plot, which doesn't look nice and is confusing for the user. How can the crosshair be restricted only to the area of the plot?

+4  A: 

Try using getpts, which doesn't create the crosshair; with getpts, you can also specify the axes you want the user to select from, as in

[x,y] = getpts(ax);

The only trouble with getpts is there's no way to limit it to exactly two points. But it does have the nice feature that the user can undo point selection by hitting DELETE, and confirm points by hitting ENTER.

looking closely at the ginput documentation, the behavior you describe is intended, and apparently unavoidable

from

doc ginput

Clicking an axes makes that axes the current axes. Even if you set the current axes before calling ginput, whichever axes you click becomes the current axes and ginput returns points relative to that axes. If you select points from multiple axes, the results returned are relative to the coordinate system of the axes they come from.

Marc
I really liked the crosshair, but that is good enough.
Lucas
you could write your own code to generate a cross hair using callbacks for the axes of interest. but that's probably the largest possible waste of time. ok maybe not the largest ever, but a top 10.
Marc