Share data from a function to pushbutton call back in gui

3 vues (au cours des 30 derniers jours)
MEHEDI HASAN
MEHEDI HASAN le 2 Mai 2015
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.

Réponses (2)

Geoff Hayes
Geoff Hayes le 3 Mai 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(....);

Image Analyst
Image Analyst le 3 Mai 2015

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by