如果你想显示的数字,而不是绘制他们,你有几种选择。一个非常简单的方法是使用MSGBOX函数打开一个对话窗口并显示一个字符串。您必须先使用INT2STR,NUM2STR或SPRINTF等函数将您的号码转换为字符串表示形式。这里有一个例子:
sumsurface = rand; %# Pick a random number
pH = rand; %# Pick another random number
str = {['sumsurface = ' num2str(sumsurface)]; ...
['pH = ' num2str(pH)]}; %# Creates a 2-by-1 cell array of strings
msgbox(str);
,这里是随后出现的对话框:
您也可以使用自己的UICONTROL函数创建静态文本框。如果要将文本框插入到现有的GUI中,这将是更好的选择。这里是你如何能初始化图形和文本框的GUI的例子:
hFigure = figure('Position',[300 300 150 70],...
'MenuBar','none');
hText1 = uicontrol('Style','text','Parent',hFigure,...
'Position',[10 40 130 20],...
'BackgroundColor',[0.7 0.7 0.7]);
hText2 = uicontrol('Style','text','Parent',hFigure,...
'Position',[10 10 130 20],...
'BackgroundColor',[0.7 0.7 0.7]);
现在你可以使用文本框的把手来更新String
属性为任何你想要显示:
set(hText1,'String',['sumsurface = ' num2str(rand)]);
set(hText2,'String',['pH = ' num2str(rand)]);
,这里是图中的样子: