Matlab 在uicontrol之间传递值

Matlab 在uicontrol之间传递值,matlab,user-interface,widget,Matlab,User Interface,Widget,我只是一个MATLAB GUI的初学者,只想知道简单的方法 我有四个小部件:2个列表uicontrols,1个按钮uicontrols,以及1个静态文本uicontrol function pushbutton1_Callback(hObject, eventdata, handles) x =get(handles.popupmenu1, 'Value') % getting the value from the popupmenu % doing something with it

我只是一个MATLAB GUI的初学者,只想知道简单的方法

我有四个小部件:2个列表
uicontrol
s,1个按钮
uicontrol
s,以及1个静态文本
uicontrol

 function pushbutton1_Callback(hObject, eventdata, handles)
 x =get(handles.popupmenu1, 'Value')  % getting the value from the popupmenu
 % doing something with it
 y=get(handles.popupmenu2, 'Value')  %  getting the value and processing it 
 % doing something with it

 total=x+y
 set(handles.text1, 'String', num2str(total))  % set to total...but
 % I really want it to be a string with a total.  like 'Your total is %s', total

您能帮我设置文本字符串吗?

这样做应该可以:

str = sprintf('your total is %s', num2str(total)); % assuming total is a number, not a string
set(handles.statictext1, 'String', str); % replace handles.statictext1 by whatever the handle your static text box is