![]() |
如何在MATLAB中的GUI中将功能中的某些内容显示到显示窗口中?
我有一个函数sumsurface ,可在以下代码中使用该函数在命令窗口中显示某些值:
if sumsurface(i) < .01 && sumsurface(i) > -.01 disp(sumsurface(i)); disp(pH(i)); end 但是,我改为在GUI的显示窗口上显示sumsurface(i)和pH(i) 。我怎样才能做到这一点? [B]回答:[/B] 如果要[I]显示[/I]数字(而不是[I]绘制[/I]数字),则有几种选择。一种非常简单的方法是使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/msgbox.html"]MSGBOX[/URL]功能打开对话框并显示字符串。您必须首先使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/int2str.html"]INT2STR[/URL] , [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/num2str.html"]NUM2STR[/URL]或[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/sprintf.html"]SPRINTF之[/URL]类的函数将您的数字转换为字符串表示[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/sprintf.html"]形式[/URL] 。这是一个例子: 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); 这是结果对话框: [IMG]https://i37.photobucket.com/albums/e77/kpeaton/example_msgbox-1.jpg[/IMG] 您还可以使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol.html"]UICONTROL[/URL]函数自己创建静态文本框。如果要将文本框插入到现有的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)]); 这是该图的样子: [IMG]https://i37.photobucket.com/albums/e77/kpeaton/example_textbox.jpg[/IMG] [url=https://stackoverflow.com/questions/2197831]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 05:09。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.