UIControl callback function problems

3 visualizaciones (últimos 30 días)
Jon
Jon el 31 de Mzo. de 2014
Comentada: Jon el 7 de Abr. de 2014
Ok, I'm trying out UIControl for the first time and I just want to write a program that asks a user to type something in after pressing a button and then displaying the string.
This is the script:
h = figure(1);
str = [];
h = uicontrol('Style', 'Pushbutton', 'String', 'A', 'Position', [255, 185, 50, 50], 'Callback', @push);
h = uicontrol('Style', 'Text', 'String', str, 'Position', [235, 250 ,100, 25]);
And the function:
function push(hObject, eventdata)
str = input('Enter value: ', 's');
set(h, 'String', str)
drawnow
end
It seems that the function doesn't recognise the variable 'h'. "Undefined function or variable 'h'.
"Error in push (line 3) set(h, 'String', str)
Error while evaluating uicontrol Callback" I know it's probably something trivial, but like I said, it's my first time in this area. Thanks for any help.

Respuesta aceptada

Dishant Arora
Dishant Arora el 31 de Mzo. de 2014
h = figure(1);
str = [];
handles.push1 = uicontrol('Style', 'Pushbutton', 'String', 'A',...
'Position', [255, 185, 50, 50])
handles.text1 = uicontrol('Style', 'Text', 'String', str,...
'Position', [235, 250 ,100, 25]);
set(handles.push1,'Callback', {@push,handles});
function push(hObject, eventdata,handles)
str = input('Enter value: ', 's');
set(handles.text1, 'String', str)
drawnow
end
  1 comentario
Jon
Jon el 7 de Abr. de 2014
Not exactly what I wanted. I just found that handle, assigned it to a variable and used that. But thanks for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by