UIControl callback function problems

3 visualizzazioni (ultimi 30 giorni)
Jon
Jon il 31 Mar 2014
Commentato: Jon il 7 Apr 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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by