UIControl callback function problems

3 Ansichten (letzte 30 Tage)
Jon
Jon am 31 Mär. 2014
Kommentiert: Jon am 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.

Akzeptierte Antwort

Dishant Arora
Dishant Arora am 31 Mär. 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 Kommentar
Jon
Jon am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by