Can't get windowButtonMotionFcn to work

This is my first time working on matlab gui and to be honest I don't know what I'm doing. Hopefully I can provide enough information to solve this. Below are the relevant parts of my program.
classdef title < handle
% code
methods
function obj = title(dirname)
% code
figH = figure(...
'WindowButtonMotionFcn' , @mouse);
end
%
function mouse(obj, hObj, varargin);
obj_han = get(hObj, 'currentpoint');
set(obj.handles.cursorX, 'String', num2str(obj_han(1)));
set(obj.handles.cursorY, 'String', num2str(obj_han(2)));
end
end
"Undefined function 'mouse' for input arguments of type 'matlab.ui.Figure'. Error while evaluating Figure WindowButtonMotionFcn"
If I leave the code of 'mouse' unchanged but change the function to:
function mouse(hObj, varargin);
and define it within function obj = title(dirname), then it works until a call to mouseButtonDwn (which executes changing WindowButtonMotionFcn to a different function, then resets WindowButtonMotionFcn to @mouse). After this the error is the same as the above.
What can I do here?

2 件のコメント

Adam
Adam 2016 年 6 月 8 日
You need to show some code, there is too little information here to understand what the setup is.
Toby Jackson
Toby Jackson 2016 年 6 月 8 日
Thanks for pointing this out, I've edited the question and provided some code. Hopefully this makes it clearer :)

サインインしてコメントする。

 採用された回答

Adam
Adam 2016 年 6 月 9 日

2 投票

You need to use @obj.mouse in your call to create the figure because the function is part of your class and so needs to have the object scope.
After that I assume 'handles' exists as a structure in your class. When I run the small snippet above with the corrected syntax obviously I get an error that 'handles' does not exist, but I imagine that is just because you have only included the bits of your class relevant to the problem.

3 件のコメント

Toby Jackson
Toby Jackson 2016 年 6 月 9 日
Cheers! I worked it out earlier today much to my relief, my eyes were simply glazing over it. It certainly didn't take you as long to realise :D as it did for me.
Adam
Adam 2016 年 6 月 9 日
One thing I meant to add, but forgot. Don't name a class 'title', you will cause the inbuilt function of the same name to be inaccessible as it will shadow your class on the path which is never a good idea. If you ever want to plot something with the normal title function you will run into errors.
I regularly run e.g.
which title
to check before naming something whether I am about to clash with a built-in function.
Toby Jackson
Toby Jackson 2016 年 6 月 9 日
That's a great tip, I'll definitely use that when naming functions in the future!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2016 年 6 月 8 日

編集済み:

2016 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by