Seting a pushbutton in a GUI
显示 更早的评论
Hello,
I made a simple GUI with two editable text boxes and a pushbutton. I just knowing how the GUI comands works. At this moment i just wanna make an adder. I already know how to get the numbers typed in the text boxes and putting them into a variable. Now, i wanna set the pushbutton to run the program and adding the numbers. The problem is: i don't know how to set up the pushbutton to run the program. Please explain easily because i still don't understand so much about programming in Matlab. thank you very much !
回答(1 个)
Paulo Silva
2011-2-21
function somar
fig=figure(1)
b1= uicontrol('Style','pushbutton',...
'String','Run Program',...
'Callback',@soma,...
'Position',[315,220,70,25]);
e1= uicontrol('Style','edit',...
'String','','Position',[315,180,70,25]);
e2= uicontrol('Style','edit',...
'String','','Position',[315,135,70,25]);
e3= uicontrol('Style','text',...
'String','','Position',[315,90,70,25]);
function soma(hObject,handles,eventdata)
set(e3,'String',str2num(get(e1,'String'))+str2num(get(e2,'String')))
end
end
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!