Can anybody fix this problem about GUI and mouse position please?
1 次查看(过去 30 天)
显示 更早的评论
I want to find the position of mouse in anywhere of screen in GUI.
C = get(0,'PointerLocation'); I knew that this code can find any position on screen and then I use it with GUI but it didn't work.
this following is my code.
function mouse()
f=figure; set (f, 'WindowButtonDownFcn', @mouseMove); % by click
function mouseMove (hObject,~)
C = get(0,'PointerLocation'); title(['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
1 个评论
回答(1 个)
Andy L
2014-8-8
编辑:Andy L
2014-8-8
Firstly You need to add end statements to each function. See the following documentation on local functions.
function [out1] = name(in1)
% some code
in2 = in1;
[out2] = subFunction(in2);
out1 = out2;
end
function [out2] = subFunction(in2)
% some other code
end
Next you are setting the property to the handle of the figure - this means your callback to mouseMove will only execute whilst your cursor is over the figure. To do what you are asking you would need to set the function for the root object.
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!