不过我建议采用guide设计gui,效率更高,并且易于调试与维护。
haedit = uicontrol('style','edit','tag','tag_a_edit', 'position',[40 120 60 20]);
hatitle = uicontrol('style','text','tag','tag_a_txt','position',[40 140 60 20],'string','a');
hadd = uicontrol('style','text','tag','tag_add_txt','position',[100 120 20 20],'string','+');
hbtitle = uicontrol('style','text','tag','tag_b_txt','position',[120 140 60 20],'string','b');
hbedit = uicontrol('style','edit','tag','tag_b_edit', 'position',[120 120 60 20]);
hcalc = uicontrol('style','push','tag','tag_calc_push','position',[180 120 20 20],'string','=');
habedit = uicontrol('style','edit','tag','tag_ab_edit', 'position',[200 120 60 20]);
set(hcalc,'callback','a = str2num(get(haedit,''string'')); b = str2num(get(hbedit,''string''));ab=a+b; set(habedit,''string'',num2str(ab))');