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.
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 Exchange에서 Creating, 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