Question about GUI programming

Hello. I am trying to make a GUI about speech recognition. i want to hold a variable from one function and use it to another one. for example. i have this code.
% --- Executes on button press in ixografisi. (record Button)
function c = ixografisi_Callback(hObject, eventdata, handles)
a = wavread('tilefwno_mix.wav');
axes(handles.axes1);
plot(a);
c = end_detection(a);
% --- Executes when selected object is changed in uipanel2.
function b = uipanel2_SelectionChangeFcn(hObject, eventdata, handles)
if (get(handles.man,'Value') == 1.0)
b = 1
else
b = 2
end
% --- Executes on button press in apotelesma. (result button)
function d = apotelesma_Callback(b, c, hObject, eventdata, handles)
if (b == 1)
g = 'm';
elseif (b == 2)
g = 'f';
end
d = demo(c,g);
I want to use the variable c from the record button and the variable b in uipanel2 in the result button. the variable b only takes 1 or 2 depends on the selection of male or female. but when i get it to the result button it has a value of 18.0032. why? can someone help me pls?
thank u
marina :)

 Respuesta aceptada

Image Analyst
Image Analyst el 15 de Abr. de 2012
Don't insert input arguments to your button callbacks. I think they expect to have (hObject, eventdata, handles) as the first three, and in that specific order. Perhaps you could try adding args to the end.
To share variables between callbacks, either get the value directly from the control with the get() function, where you pass in the known "tag" name of the control and ask for the 'value' property,
controlValue = get(handles.controlTag, 'Value');

3 comentarios

Image Analyst
Image Analyst el 15 de Abr. de 2012
You can take the variable b in the uipanel2 callback and send it to setappdata(). Then in the result button callback, call getappdata(). Like it says in the FAQ:
% Do this to save variables to your figure's workspace.
% handles.GUIHandle is the "Tag" property of your main GUI figure.
% Double-click figure to bring up the "Property Inspector" in GUIDE.
setappdata(handles.GUIHandle, 'yourVariable', yourVariable)
% Do this to retrieve variables from your figure's workspace.
yourVariable = getappdata(handles.GUIHandle , 'yourVariable')
Or you can attach it as a new member to your handles structure:
handles.b = b; % In the uipanel2 callback function.
b = handles.b; % in the result button callback function.
marina
marina el 15 de Abr. de 2012
??? Reference to non-existent field 'GUIHandle'.
Error in ==> testing_gui2>apotelesma_Callback at 97
c = getappdata(handles.GUIHandle , 'c')
marina
marina el 15 de Abr. de 2012
ok done it.
thank u very much! :)

Iniciar sesión para comentar.

Más respuestas (1)

marina
marina el 15 de Abr. de 2012

0 votos

if i can ask something else.
i have the main gui window. can i open through a button an extra gui window to perform some tasks and then close it and continue working in the main window??

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Abr. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by