1

我只是 MATLAB GUI 的初学者,只想知道简单的方法来做到这一点。

我有四个小部件:2 个列表uicontrol、1 个按钮uicontrol和 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

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

4

1 回答 1

2

应该这样做:

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
于 2013-11-08T14:31:08.280 回答