フィルターのクリア

How to get cursor info in UIaxes

24 ビュー (過去 30 日間)
Junfeng Liang
Junfeng Liang 2022 年 4 月 20 日
回答済み: chrisw23 2022 年 4 月 21 日
Hi
I am trying to duplicate the code below in the app designer. This code return the point selected with the mouse from a plot in the figure. I try to run it in the app designer. But I don't know how to pass the handle of my UIaxes to "dcm_obj"
x = linspace(0,10,150);
y = cos(5*x);
fig = figure;
plot(x,y,'Color',[0,0.7,0.9])
title('2-D Line Plot')
xlabel('x')
ylabel('cos(5x)')
% Enable data cursor mode
datacursormode on
dcm_obj = datacursormode(fig);
% Set update function
set(dcm_obj,'UpdateFcn',@myupdatefcn)
% Wait while the user to click
disp('Click line to display a data tip, then press "Return"')
pause
% Export cursor to workspace
info_struct = getCursorInfo(dcm_obj);
if isfield(info_struct, 'Position')
disp('Clicked positioin is')
disp(info_struct.Position)
end
function output_txt = myupdatefcn(~,event_obj)
% ~ Currently not used (empty)
% event_obj Object containing event data structure
% output_txt Data cursor text
pos = get(event_obj, 'Position');
output_txt = {['x: ' num2str(pos(1))], ['y: ' num2str(pos(2))]};
end
How can I do it?

回答 (2 件)

chrisw23
chrisw23 2022 年 4 月 21 日
In Appdesigner you have the option to evaulate the 'CurrentPoint' property of your Axes control within a MouseMoveCallback method.

Walter Roberson
Walter Roberson 2022 年 4 月 20 日
event_obj.Target will be the handle to the graphics object. You can use ancestor(event_obj.Target, 'axes') if you need the UIAxes

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by