UIControl callback function problems

5 vues (au cours des 30 derniers jours)
Jon
Jon le 31 Mar 2014
Commenté : Jon le 7 Avr 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.
  1 commentaire
Jon
Jon le 31 Mar 2014
Can anybody help?

Connectez-vous pour commenter.

Réponse acceptée

Dishant Arora
Dishant Arora le 31 Mar 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 commentaire
Jon
Jon le 7 Avr 2014
Not exactly what I wanted. I just found that handle, assigned it to a variable and used that. But thanks for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by