From: Emma on
Bump... anyone???
Scott is right, I've tried using WindowButtonMotionFcn to track the cursor, but the coordinates stop being printed while ginput is in effect.


"Scott Smith" <scottsmith(a)mat-gui.com> wrote in message <ef45340.0(a)webcrossing.raydaftYaTP>...
> Wes wrote:
> >
> >
> > Is there any code to display the coordinate of a cursor in ginput
> > simulatenously while moving the cursor without clicking the mouse
> > button?
> >
> > Thanks
>
> Hi Wes,
>
> I tried defining a WindowButtonMotionFcn callback function for a
> figure to track the mouse position while ginput() is called, however
> ginput() takes over mouse tracking and the WindowButtonMotionFcn
> callback doesn't respond until you hit enter to end the ginput()
> function. Anyone else have ideas on this?
>
> You can always define your own mouse cursor motion tracker and button
> capture by defing WindowButtonMotionFcn and WindowButtonDownFcn
> callbacks. This way you can easily track the mouse position and
> button clicks. For a GUI program the code may look something like
> this:
>
> % mouse motion callback function
> function figure_WindowButtonMotionFcn(hObject, event_data, handles)
>
> % get position of mouse in figure coordinates
> mouse_pos_fig = get(handles.fig, 'CurrentPoint');
>
> % get position of mouse in axes coordinates and display using
> text box
> % that follows the mouse
> mouse_pos_axes = get(handles.axes,'CurrentPoint');
> set( handles.text, ...
> 'Position', [mouse_pos_fig(1) mouse_pos_fig(2) 125 20],
> ...
> 'String', ['x = ' num2str(mouse_pos_axes(1,1)) ', y = '
> num2str(mouse_pos_axes(1,2))]);
>
> handles.mouse_pos_fig = mouse_pos_fig;
> handles.mouse_pos_axes = mouse_pos_axes;
> guidata(hObject, handles);
>
> % mouse button callback function
> function figure_WindowButtonDownFcn(hObject, event_data, handles)
>
> % check if first button selection has occured and accumulate x,y
> points
> if handles.first_select
> handles.x = [handles.x mouse_pos_axes(1,1)];
> handles.y = [handles.y mouse_pos_axes(1,2)];
> else
> handles.x = mouse_pos_axes(1,1);
> handles.y = mouse_pos_axes(1,2);
> handles.first_select = 1;
> end
>
> plot(x, y, 'Parent', handles.axes);
> guidata(hObject, handles);
>
> This may be more complicated than just calling ginput although it is
> more flexible and general as well.
>
> For more info on Handle Graphics and GUI programming see MATLAB
> Advanced GUI Development, ISBN 1598581813, found on Amazon.com,
> bn.com, or www.mat-gui.com.
>
> Regards,
> Scott