我只是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
你能帮我设置文字字符串吗?
答案 0 :(得分: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