How to get cursor information of data tips using call back of a push buttion?

1 次查看(过去 30 天)
I have a fairly simple code. All I want is user to select multiple data tips (Alt+left mouse button) from a plot and on clicking a push button, the position and data index of the data tips be written in a structure. The command, c_info = cursorMode.getCursorInfol; gives me the required output but not when used in a callback function. Please suggest a way to assign the above command to a push button. Thanks for the help! First draft of the code is herewith:
function [] = GUI_me(varargin)
fh = figure('units','pixels',...
'position',[200 100 500 560],...
'menubar','none',...
'name','GUI_1',...
'numbertitle','off',...
'resize','off');
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fh);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 180 40],...
'fontsize',14,...
'string','Done',...
'callback',{@pb_call});
pb2 = uicontrol('style','push',...
'units','pix',...
'position',[300 10 180 40],...
'fontsize',14,...
'string','Clear data tips',...
'callback',{@pb2_call});
function [] = pb2_call(varargin) % Clears user selected data tips
cursorMode = datacursormode(gcf);
cursorMode.removeAllDataCursors();
function [] = pb_call(varargin) % Returns the position and data index of selected data tips
% Callback for pushbutton.
cursorMode = datacursormode(gcf);
c_info = cursorMode.getCursorInfo;

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by