Share data from a function to pushbutton call back in gui

4 次查看(过去 30 天)
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.

回答(2 个)

Geoff Hayes
Geoff Hayes 2015-5-3
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(....);

Image Analyst
Image Analyst 2015-5-3

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by