Share data from a function to pushbutton call back in gui
2 views (last 30 days)
Show older comments
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i need data1 in this function for several operation
function output_txt = labeldtips(obj,event_obj,hdt)
dcs=hdt.DataCursors;
pos = get(dcs(1),'Position');
output_txt{1} = ['X: ', num2str(pos(1))];
output_txt{2} = ['Y: ', num2str(pos(2))];
data1=pos(2);
Can anyone help me ? Thanks in advance.
0 Comments
Answers (2)
Geoff Hayes
on 3 May 2015
Mehedi - if you want data1 to be used by your pushbutton3 callback, then just add this variable to the output parameter list of the function. So something like
function [data1,output_txt] = labeldtips(obj,event_obj,hdt)
dcs=hdt.DataCursors;
pos = get(dcs(1),'Position');
output_txt{1} = ['X: ', num2str(pos(1))];
output_txt{2} = ['Y: ', num2str(pos(2))];
data1=pos(2);
would do the trick. Call it from your callback as
function pushbutton3_Callback(hObject, eventdata, handles)
% do stuff
% call function
[data1,output_txt] = labeldtips(....);
0 Comments
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!