External mouse track function

조회 수: 2 (최근 30일)
Jakob Sørensen
Jakob Sørensen 2012년 4월 16일
Hey,
I made a function to track the cursor over certain handles, but for the sake of simplicity, i would like that to be an external function (right now its in the bottom of the GUI). I want to apply it using:
set(hObject, 'WindowButtonMotionFcn',trackCursor(uicontrol,hObject));
Where 'uicontrol' is the name of the axes that should be tracked (like handles.axes1). But when I use the set, I can't figure out, how to obtain the function output, which is x and y, both are scalars. I have also tried saving them into the handle, but this results in an
Error using trackCursor
Too many output arguments.
The functions works fine within the GUI, so it's only the syntax that seems to cause me trouble. Any help would be greatly appreciated, thank you!
- Jake

채택된 답변

Jan
Jan 2012년 4월 16일
This:
... track the cursor over certain handles...
and
Where 'uicontrol' is the name of the axes that should be tracked (like handles.axes1)
is not getting clear to me.
Perhaps you are looking for:
set(hObject, 'WindowButtonMotionFcn', {@trackCursor, handles.axes1});
...
And the separate function:
function trackCursor(hObj, EventData, Axes1)
handles = guidata(hObj);
P = get(Axes1, 'CurrentPoint');
handles.x = P(1, 1);
handles.y = P(1, 2);
guidata(hObj, handles);
But this contains some guessing of want you might need.
  댓글 수: 1
Jakob Sørensen
Jakob Sørensen 2012년 4월 16일
I have to say you're pretty good at guessing. The thing I had trouble with, was passing additional input into the trackCursor function. Sorry for not being very clear about that. And thanks a lot for the help, both of you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 16일
WindowButtonMotionFcn cannot return any values. It can, however, be a function that affects shared variables.
Note that in the syntax you would like to use, trackCursor(uicontrol,hObject) would have to return a function handle to a routine that accepts a src and event object (all callbacks are passed those) and returns nothing.
  댓글 수: 1
Jakob Sørensen
Jakob Sørensen 2012년 4월 16일
But exactly how do i make the call then? And how do I make my function accept this call and save the xy-coords in the handles?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by