et ( gco,Units HorizontalAlignment','left mmdraw是精通 MATLAB工具箱中另一个有用GU函数,它与 mmtext十分相似,但更为复杂, 此函数允许用户用鼠标在当前的坐标轴上画线并设置线的属性 function mmdraw(argl, arg2, arg3, arg4, arg5, arg6, arg7) %MMDRAW Draw a Line and Set Properties Using Mouse %oMMDRAW Draw a Line in the current axes using to the mose %Click at the starting point and drag to the end point %In addition, properties can be given to the line %Properties are given in pairs, e.g., MMDRW name vale ‰ Properties: %NAME value (defult %color ly m crg biw kor an rgb in quotes: '[rg b] %style ---:}- %omark %width points for linewidth 10.51 %size points for marker size 16; %Examples %MMDRAW color r width 2 sets color to red and width to 2 points%MMDRAW mark+ size 8 set marker type to +and size to 8 points %MMDRAW color'[150]' set color to orange %Copyright (c)1996 by Prentice-Hall, Inc global MMDRAW HI MMDRAW EVAL if nargin==0 argl=color: arg2=w: arg3=style: arg4=: if isstr(arg l)% initial call, set thing up if isempty(Hf), error(No Figure Available. '),end Ha=findobj(Hf, 'Type,axes); if isempty(Ha), error( No Axes in Current Figure. ), end et(Hf, 'Pointer,'Crossh,.%set up callback for line star WindowButton DownFcn','mmdraw(1)') MMDRAW EVAL='mmdrw(99):%set up string to set attributes for i=1 Feval(sprintf(arg%.of',i)); MMDARW EVAL=IMMDARW EVAL ehe MMDARW EVALFIMMDARW EVAL,): elseif argl==1 %callback is line start point po fp(1,1:2))%s
set(gco, ' Units ' , ' data ' ,... ' HorizontalAlignment ' , ' left ' ,... mmdraw是精通MATLAB工具箱中另一个有用GUI函数,它与mmtext十分相似,但更为复杂, 此函数允许用户用鼠标在当前的坐标轴上画线并设置线的属性。 function mmdraw(arg1,arg2,arg3,arg4,arg5,arg6,arg7) %MMDRAW Draw a Line and Set Properties Using Mouse. %MMDRAW Draw a Line in the current axes using to the mose. %Click at the starting point and drag to the end point %In addition,properties can be given to the line. %Properties are given in pairs,e.g.,MMDRW name vale... %Properties: %NAME VALUE (defult) %color [y m c r g b {w} k] or an rgb in quotes: ' [r g b] %style [-----{:}--.] %mark [0 + . * x] %width points for linewidth {0.5} %size points for marker size {6} %Examples: %MMDRAW color r width 2 sets color to red and width to 2 points%MMDRAW mark + size 8 set marker type to +and size to 8 points %MMDRAW color ' [1 5 0] ' set color to orange %Copyright (c) 1996 by Prentice-Hall,Inc. global MMDRAW_Hl MMDRAW_EVAL if nargin==0 arg1= ' color ' ;arg2= ' w ' ;arg3= ' style ' ;arg4= ' : ' ;nargin=4; end if isstr(arg1) % initial call,set thing up if isempty(Hf),error( ' No Figure Available. ' ),end Ha=findobj(Hf, ' Type, ' axes ' ); if isempty(Ha),error( ' No Axes in Current Figure. ' ),end set(Hf, ' Pointer ' , ' Crossh ' ,...%set up callback for line star ' BackingStore ' , ' off ' ,... ' WindowButtonDownFcn ' , ' mmdraw(1) ' ) figure(Hf) MMDRAW_EVAL= ' mmdrw(99);%set up string to set attributes for i=1:nargin argi=eval(sprintf( ' arg%.of ' ,i)); MMDARW_EVAL=[MMDARW_EVAL ' , ' ' arg ' ' ' ' ]; end MMDARW_EVAL=[MMDARW_EVAL ,) ' ]; elseif arg1==1 % callback is line start point fp=get(gca, ' CurrentPoint ' ); %start point set(gca, ' Userdata ' ,fp(1,1:2)) %store in axes userdata
set(gcf, 'Window ButtonMotionF draw(2) Window ButtonUpFcn aw(3)") elseif arg l==2 callback is mouse motion p=get( gca, 'Current Point): cp=cp(1, 1: 2): fp=get(gca,Userdata): HI-line('Xdata, [fp():cp(I)],'Ydata, [fp(2):cp(2)] Color', 'w',' LineStyle,': Clipping,'off if -isempty(MMDRAW HL)% delete prior line if it exsts elete(MMDRAW HL) MMDRAW HL=HI: store current line handle elseif arg1==3 % callback is line end point, finish up set(gcf, Point,arrow, BackingStore’,'on', Window Button DownFcn',,, Window ButtonMotionFcn',' mmtext(2) indow ButtonUpFcn',') set(gca, 'Userdata, set(MMDRAW HL, 'EraseMode','normal ')% render line better eval( MMDRAW EⅤAL) MMDRAW EVAL=D elseif arg1==99 process line properties name=eval(sprintf('arg%of, 1), ) get name argument al(sprintf(arg%.of',i+1), ) % get if strcmp(name,color) if value(l=[, value=eval( value): end set(MMDRAW HL, 'color', value) elseif strcmp( name, 'style) set(MMDRAW HL, 'Lineatyle', value elseif strcmp( set(MMDRAW HL, ' Linestyle elseif strcmp( name, ' width') s(eval(value)) set(MMDRAW HL, 'LineWidth', value value=abs(eval(value)) set(MMDRAW HL, Marker Size, value) end end AMDRAW HL和
set(gcf, ' WindowButtonMotionFcn ' , ' mmdraw(2) ' ,... ' ' WindowButtonUpFcn ' , ' mmdraw(3) ' ) elseif arg1==2 % callback is mouse motion cp=get(gca, ' CurrentPoint ' );cp=cp(1,1:2); fp=get(gca, ' Userdata ' ); H1=line( ' Xdata ' ,[fp(1);cp(1)], ' Ydata ' ,[fp(2);cp(2)],... ' EraseMode ' , ' Xor,... ' Color ' , ' w ' , ' LineStyle ' , ' : ' ,... "Clipping ' , ' off ' ; if ~isempty(MMDRAW_HL) % delete prior line if it exsts delete(MMDRAW_HL) end MMDRAW_HL=H1; % store current line handle elseif arg1==3 % callback is line end point,finish up set(gcf, ' Point ' , ' arrow,... ' BackingStore ' , ' on ' ,... ' WindowButtonDownFcn ' , ' ,... ' WindowButtonMotionFcn ' , ' mmtext(2) ' ,... ' WindowButtonUpFcn ' , ' ' ) set(gca, ' Userdata ' ,[]) set(MMDRAW_HL, ' EraseMode ' , ' normal ' ) % render line better eval(MMDRAW_EVAL) MMDRAW_EVAL=[]; elseif arg1==99 % process line properties for i=2:2:nargin-1 name=eval(sprintf( ' arg%.of ' ,i),[]); % get name argument vale=eval(sprintf( ' arg%.of ' ,i+1),[]); % get value argument if strcmp(name, ' color ' ) if value(1)== ' [ ' ,value=eval(value);end set(MMDRAW_HL, ' color ' ,value) elseif strcmp(name, ' style ' ) set(MMDRAW_HL, ' Lineatyle ' ,value) elseif strcmp(name, ' mark ' ) set(MMDRAW_HL, ' Linestyle ' ,value) elseif strcmp(name, ' width ' ) value=abs(eval(value)); set(MMDRAW_HL, ' LineWidth ' ,value) elseif strcmp(name, ' size ' ) value=abs(eval(value)); set(MMDRAW_HL, ' MarkerSize ' ' ,value) end end MMDRAW_HL=[]; end
虽然这里说明太长,但精通 MATLAB工具箱中的函数 mmsetc和 mmsetf都是使用递归、全局变 量和' UserData'属性的GUI函数的直观例子。也许愿意看一下 mmsetclr M文件,它是函数 mmsetc文件的脚本M文件。比较这两个文件,可以了解到,为实现各种GUIM文件要做出一些 折衷。 21.9对话框和请求程序 MATLAB具有建立对话框和’请求的几个有用工具。对话框是弹出显示的单独窗口,它 显示信息字符串。对话框含有一个或多个按钮键以供用户输入。请求框是在弹出显示的单独窗 口,利用鼠标或键盘获得输入,并返回信息给调用函数。 对话框 所有 MATLAB的对话框都是基于函数 dialog,它的帮助文本如下 >>help dialog DIALOG displays a dialog box FIG=DIALOG(pl, vl. )displays a dialog box. valid param/value pairs include error I warning I help I question strI Resize on I off BackgroundColor Color Spe Button String Button1 String I Button2String I Button call Button Callback Button2 Callback I oregroundcolor Positie [x y width height x y- centers around screen point TextString strI tels normal I cent I inches I User Data matrIx Note: Until dialog becomes built-in, set and get are not valid for dalong objects At most three buttons are allowed The callbacks are ignored for"question"dialogs If Button Strings/Button Calls are unspecified then it defaults to a single"ok" button which removes the figure There's still problems with making the question dialog modal The entire parameter name must be passed in (i.e. no automatic completion) Nothing beeps yet See also ERRORDLG, HELPDLG, QUESTDLG 注意:对话窗本身不是句柄图形对象,而是由一系列句柄图形对象构成的M文件。对话窗口是 图形,包括与框架、编辑和按钮 uncontrol对象共存的坐标轴。在将来的版本中, dialog可能成 为具有更多功能的内置函数。缺省的对话框是一个帮助对话框,它是由' Default help string 字符串和标有’OK'的按钮键组成的编辑文本框。作为例子,键入> dialog o
虽然这里说明太长,但精通MATLAB工具箱中的函数mmsetc和mmsetf都是使用递归、全局变 量和 ' UserData ' 属性的GUI函数的直观例子。也许愿意看一下mmsetclr M文件,它是函数 mmsetc文件的脚本M文件。比较这两个文件,可以了解到,为实现各种GUI M文件要做出一些 折衷。 21.9 对话框和请求程序 MATLAB具有建立对话框和 ' 请求 ' 的几个有用工具。对话框是弹出显示的单独窗口,它 显示信息字符串。对话框含有一个或多个按钮键以供用户输入。请求框是在弹出显示的单独窗 口,利用鼠标或键盘获得输入,并返回信息给调用函数。 对话框 所有MATLAB的对话框都是基于函数dialog,它的帮助文本如下 >>help diolog DIALOG displays a dialog box. FIG = DIALOG (pl ,vl....)displays a dialog box. valid param/value pairs include Style error | warning | help | question Name string Replace on | off Resize on | off BackgroundColor ColorSpec ButtonString ' Button1String | Button2String | ... ' ButtonCalls ' ButtonCallback | Button2Callback | ... ' ForegroundColor ColorSpec Position [x y width height] [x y] - centers around screen point TextString string Units pixels | normal | cent | inches | points UserData matrix Note: Until dialog becomes built-in, set and get are not valid for dialong objects. At most three buttons are allowed. The callbacks are ignored for"question"dialogs. If ButtonStrings /ButtonCalls are unspecified then it defaults to a single "ok" button which removes the figure. There ' s still problems with making the question dialog modal. The entire parameter name must be passed in. (i.e. no automatic completion). Nothing beeps yet. See also ERRORDLG,HELPDLG,QUESTDLG 注意:对话窗本身不是句柄图形对象,而是由一系列句柄图形对象构成的M文件。对话窗口是 图形,包括与框架、编辑和按钮uicontrol对象共存的坐标轴。在将来的版本中,dialog可能成 为具有更多功能的内置函数。缺省的对话框是一个帮助对话框,它是由 ' Default help string ' 字符串和标有 ' OK ' 的按钮键组成的编辑文本框。作为例子,键入>> dialog
预先定义的对话框是由函数 helpdlg, enordlg, warndlg和 gucstdlg建立。 helpdlg和 warndlg接受文本字符串和窗口标题字符串作为输入参量。 errordlo接收 Replace’变量作为输 入。除了 questdlg,所有上述函数都产生类似的对话框,它有各自缺省的标题和文本字符串 标有'OK'的单个按钮,则关闭对话框。 helpdlg帮助文本是 > help helpdlg HELPDLG: Displays a help dialog box HANDLE=HELPDLG(HELPSTRING, DLGNAME)displays the message Help String in a dialog box with title DlGNAMe if a help dialog with that name is aldeady on the screen it is brought to the front Otherwise it is created ee also DIALOG 帮助信息 Helpdlg:显示一个帮助文本框 HANDLE= HELPDLG( HELPSTRING, DLGNAME)在对话框中显示标题为 dlgname的 帮助信息 helpstring。如果名为 dlgname的帮助对话框己在屏幕上显示,则引到屏幕正 面,否则就建立该帮助对话框 参阅: dialog warndlg的帮助文本是: >>help warndlg WARNDLG Creates a warning dialog box HANDLE=WARNDLG(WARNSTR, DLGNAME)creates a warning diolog box which displays WaRNSTR in a window named DLGNAME. A pushbutton labeled OK must be pressed to make the warning box disappear. See also: DIALOG errordlg的帮助文本是 >>help errordlg ERRORDLG Creates an error dialog box HANDLE=ERRORDLG(ERRORSTR, DLGNAME, Replace) creates an er dialog box which diplays ERRORSTR in a window nnnamed DLGNAMEA pushbutton labeled OK must be pressed to make the error box disappear If REPLACE=on and an error dialog with Name DLGNAMe already exits, it is simply brought to the front(no new dialog is created) See also DIALOG
预先定义的对话框是由函数helpdlg, enordlg, warndlg和gucstdlg建立。helpdlg和 warndlg接受文本字符串和窗口标题字符串作为输入参量。errordlg接收 ' Replace ' 变量作为输 入。除了questdlg,所有上述函数都产生类似的对话框,它有各自缺省的标题和文本字符串。 标有 ' OK ' 的单个按钮,则关闭对话框。helpdlg帮助文本是: >> help helpdlg HELPDLG: Displays a help dialog box. HANDLE=HELPDLG(HELPSTRING,DLGNAME) displays the message HelpString in a dialog box with title DLGNAME. if a help dialog with that name is aldeady on the screen, it is brought to the front.Otherwise it is created. See also:DIALOG 帮助信息 Helpdlg:显示一个帮助文本框 HANDLE = HELPDLG(HELPSTRING,DLGNAME)在对话框中显示标题为dlgname的 帮助信息helpstring。如果名为dlgname的帮助对话框已在屏幕上显示,则引到屏幕正 面,否则就建立该帮助对话框。 参阅:dialog warndlg的帮助文本是: >>help warndlg WARNDLG Creates a warning dialog box. HANDLE=WARNDLG(WARNSTR,DLGNAME) creates a warning diolog box which displays WARNSTR in a window named DLGNAME.A pushbutton labeled OK must be pressed to make the warning box disappear. See also:DIALOG errordlg的帮助文本是 >>help errordlg ERRORDLG Creates an error dialog box HANDLE = ERRORDLG(ERRORSTR,DLGNAME,Replace) creates an error dialog box which diplays ERRORSTR in a window nnnamed DLGNAME.A pushbutton labeled OK must be pressed to make the error box disappear.If REPLACE= ' on ' and an error dialog with Name DLGNAME already exits,it is simply brought to the front (no new dialog is created). See also :DIALOG
帮助信息 ERRORDLO:建立出错对话框 HANDLE= ERRORDLG( ERRORS TR, DLGNAME, REPLACE)建立显示出错信息 errorstr y、名为 dlgname的出错对话框,要消除出错信息对话框,必须揿下标记为ok的 按钮,如果 replace='on'并且名为 dignam的出错对话框已经存在,则就引到屏幕正 面,不再建立新的对话框。 参阅: dialog 提问的对话框稍有不同,前三种函数只显示一个按钮键并返回对话框图形对象的句柄。函数 如下,显示两个或三个按钮键,返回由用户所选的按钮的标志字符串。que的帮助文本 >>help qeustdlg QEUSTDLG Creates a question dialog box. CLICK=QUESTDLG(Q, YES, O, CANCEL, DEFAULT) creates a question dialog box which displays Q. Up to three pushbuttons with strings given by YES, NO, and CANCEL, will appear along with Q in the dialog. The dialog wil be destroyed turning the string CliCK depending on which button is clicked DefAULT is the default button numbe 帮助信息 QUESTDLG:建立问题对话框 CLCK= QVESTDLG(O,YES,NO, CANCEL, DEFAULT建立显示信息Q的问题对 话框。至多有三个按钮具有由YES,NO和 CANCEL给定的字符串,按钮与Q一起,显 示在对话框中。根据所击的按钮返回字符串 CLICK对话框消失。 DEFAULT是缺省的 按钮数。 下面是函数的片断,说明了函数中提问对话框的应用: questionI=Change color map to copper? response l=questdlg(questionI, 'Sure,Nope, Maybe, 2); if stroma(respo map(copper) elseif tromp(response1,'Maybe) wandle( That response does not compute! ) idly(' Please make up ye lo'); if colormap(copper ) 请求程序
帮助信息 ERRORDLG:建立出错对话框 HANDLE=ERRORDLG(ERRORSTR,DLGNAME ,REPLACE) 建立显示出错信息 errorstr、名为dlgname的出错对话框,要消除出错信息对话框,必须揿下标记为OK的 按钮,如果replace= ' on ' 并且名为digname的出错对话框已经存在,则就引到屏幕正 面,不再建立新的对话框。 参阅:dialog 提问的对话框稍有不同,前三种函数只显示一个按钮键并返回对话框图形对象的句柄。函数 questdlg显示两个或三个按钮键,返回由用户所选的按钮的标志字符串。questdlg的帮助文本 如下: >>help qeustdlg QEUSTDLG Creates a question dialog box. CLICK=QUESTDLG(Q,YES,O,CANCEL,DEFAULT) creates a question dialog box which displays Q.Up to three pushbuttons, with strings given by YES,NO,and CANCEL,will appear along with Q in the dialog.The dialog wil be destroyed returning the string CLICK depending on which button is clicked.DEFAULT is the default button number. 帮助信息 QUESTDLG:建立问题对话框 CLICK=QVESTDLG(Q,YES,NO,CANCEL,DEFAULT)建立显示信息Q的问题对 话框。至多有三个按钮具有由YES,NO和CANCEL给定的字符串,按钮与Q一起,显 示在对话框中。根据所击的按钮返回字符串CLICK对话框消失。DEFAULT是缺省的 按钮数。 下面是函数的片断,说明了函数中提问对话框的应用: question1= ' Change color map to copper? ' ; response1=questdlg(question1, ' Sure ' , ' Nope ' , ' Maybe ' ,2); if stromp(response1, ' Sure ' ) colormap(copper); elseif stromp(response1, ' Maybe ' ) wandlg( ' That response does not compute! ' ); response2=questdly([ ' Please make up your mind.| ' question1], ' Yes ' , ' No ' ); if stromp (response2, ' Yes ' ) colormap(copper); end end 请求程序
请求程序通过对话框获取用户的输入。请求程序是内置式GU函数,它使用平台原有的窗 口系统建立外观熟悉的请求程序。 函数 uigecfile和 uiputfile是所有平台上都有的内置式函数,用于交互地获得文件名,从而 调用函数用它读取文件中数据或将数据存于文件中。 uigetfilel的帮助文本是: UIGETFILE Interactively retrieve a filename by displaying a dialog box. [FILENAME, PATHNAME]=UIGETFILE(' filter Spec,'dialogTitle,X, Y) displays a dialog box for the user to fill in, and returns the filename and path strings. A successful return occurs only if the file exists lf the user selects a file that does not exist an error message is displayed, and control returns to the dialog box The user may then enter another filename, or press the Cancel button All parameters are optional, but if one is used, all previous parameters must also be used The felterSpec parameter determines the initial display of files he dialog box. For example *.m' lists all the MATLAB M-files Parameter 'dialogTitle' is a string containing the title of the dialog The X and Y parameters define the initial position of the dialog box in units of pixels. Some systems may not support this option The output variable FILENAME is a string containing the mane of the file selected in the dialog box. If the user presses the Cancel button or if any error occurs, it is set to O the file selected in the dialog box. If the user presses the Cancelof The output parameter PATHNAME is a string containing the pa button or if any error occurs, it is set to O See alSo Uiputfile 帮助信息 UIGETFILE:通过显示对话框交互式地检索文件名 FILENAME, ATHNAME]= UIGETFILE(' filterspec’",' dialogite',x,y)显示一个 对话框,让用户输入,并返回路径和文件名字符串。仅当文件存在时,才成功地返 回。如果用户选择了一个并不存在的文件,就显示出错信息,控制框返回到对话框 用户可以输入另一个文件名或揿下 Cancel按钮。 所有输入参数都是可任选的,如果用其中之一个,也必须使用所有先前参数。 参数 filespec决定对话框中文件的初始显示。例如*m'列出的所有M文件 参数 dialogite是对话框标题字符串 以象素为单位参数x,y定义对话框的初始位置,有些系统可能不支持这个选项
请求程序通过对话框获取用户的输入。请求程序是内置式GUI函数,它使用平台原有的窗 口系统建立外观熟悉的请求程序。 函数uigecfile和uiputfile是所有平台上都有的内置式函数,用于交互地获得文件名,从而 调用函数用它读取文件中数据或将数据存于文件中。uigetfile的帮助文本是: >>help uigetfile UIGETFILE Interactively retrieve a filename by displaying a dialog box. [FILENAME,PATHNAME]=UIGETFILE( ' filterSpec ' , ' dialogTitle ' ,X,Y) displays a dialog box for the user to fill in,and returns the filename and path strings.A successful return occurs only if the file exists.If the user selects a file that does not exist, an error message is displayed,and control returns to the dialog box. The user may then enter another filename,or press the Cancel button. All parameters are optional,but if one is used,all previous parameters must also be used. The felterSpec parameter determines the initial display of files in the dialog box.For example ' *.m ' lists all the MATLAB M-files. Parameter ' dialogTitle ' is a string containing the title of the dialog box. The X and Y parameters define the initial position of the dialog box in units of pixels. Some systems may not support this option. The output variable FILENAME is a string containing the mane of the file selected in the dialog box.If the user presses the Cancel button or if any error occurs,it is set to 0. The output parameter PATHNAME is a string containing the path of the file selected in the dialog box. If the user presses the Cancel button or if any error occurs,it is set to 0. See also UIPUTFILE. 帮助信息 UIGETFILE:通过显示对话框交互式地检索文件名 [FILENAME,ATHNAME]=UIGETFILE( ' filterspec ' , ' dialogtitle ' ,x,y)显示一个 对话框,让用户输入,并返回路径和文件名字符串。仅当文件存在时,才成功地返 回。如果用户选择了一个并不存在的文件,就显示出错信息,控制框返回到对话框。 用户可以输入另一个文件名或揿下Cancel按钮。 所有输入参数都是可任选的,如果用其中之一个,也必须使用所有先前参数。 参数filteospec决定对话框中文件的初始显示。例如 ' *.m ' 列出的所有M文件。 参数 ' dialogtitle ' 是对话框标题字符串。 以象素为单位参数x,y定义对话框的初始位置,有些系统可能不支持这个选项
输出变量 filename是对话框内所选文件的名称字符串。如果用户揿了取消按钮或有错 误发生, filename的值设置为o 输出参数 pathname是对话框内所选文件的路径名字符串。如果用户揿了取消按钮或有 错误发生, pathname的值设置为0。 参阅 下面的例子说明了在函数中如何利用 uigetfile,交互式地检索ASCI码数据文件,并绘制正弦数 据 Ask the user for a file name [datafile datapath]=uigetfile('. dat',' Choose a data file): If the user selected an existing file, read the data. %o (The extra quotes avoid problems with spaces in file or path names on the Macintosh platform) %Then determine the variable name from the file name copy the data to a variable, and plot the data if datafile eval('load('''datapath datafile)') X-eva al(strtok( datafile. ' plot(x, sin( x)) 请求程序不接受并不存在的文件名。这种情况可能发生的原因是用户在请求程序中把文件名输 入到文件框中。 Macintosh版本无文本框的,用户必须选择一个存在的文件或揿下 Cancel按钮以 退出请求程序 函数 uiputfile与函数 uigetfie分相似:输入参量相似,而且两者均返回文件和路径字符 的帮助文件是 > help uiputfile UIPUTFILE Interactively retrieve a filename by displaying a dialog box FILENAME, PATHNAME]=UIPUTFILEC'inifFile','dialogTitle) displays a dialog box and returns the filename and path strings The init File paramete determines the initial display of files in the dialog box. Full file name specifications as well as wildcards are allowed. For example, newfile. m'initializes the display that particular file and lists all othe existing. m files. This may be used to provide a default file mane. A wildcard specification such as m' lists all the existing matlab m-files Parameter'dialogTitle is a string containing the title of the dialog The output variable FIlENAME is a string containing the name of the file selected in the dialog box. If the user presses the Cancel butto or if any error occurs, it is set to O
输出变量filename是对话框内所选文件的名称字符串。如果用户揿了取消按钮或有错 误发生,filename的值设置为0。 输出参数pathname是对话框内所选文件的路径名字符串。如果用户揿了取消按钮或有 错误发生,pathname的值设置为0。 参阅 uiputfile 下面的例子说明了在函数中如何利用uigetfile,交互式地检索ASCII码数据文件,并绘制正弦数 据 % Ask the user for a file name. [datafile datapath]=uigetfile( ' .dat ' , ' Choose a data file ' ); % If the user selected an existing file,read the data. % (The extra quotes avoid problems with spaces in file or path names % on the Macintosh platform.) % Then determine the variable name from the file name, % copy the data to a variable,and plot the data. if datafile eval([ ' load( ' ' ' datapath datafile ' ' ' ) ' ] ' ); x=eval(strtok(datafile. ' . ' ); plot (x,sin(x)); end 请求程序不接受并不存在的文件名。这种情况可能发生的原因是用户在请求程序中把文件名输 入到文件框中。Macintosh版本无文本框的,用户必须选择一个存在的文件或揿下Cancel按钮以 退出请求程序。 函数uiputfile与函数uigetfie十分相似:输入参量相似,而且两者均返回文件和路径字符 串,uiputfile的帮助文件是 >> help uiputfile UIPUTFILE Interactively retrieve a filename by displaying a dialog box. [FILENAME,PATHNAME]=UIPUTFILE( ' inifFile ' , ' dialogTitle ' ) displays a dialog box and returns the filename and path strings. The initFile paramete determines the initial display of files in the dialog box.Full file name specifications as well as wildcards are allowed.For example, ' newfile.m ' initializes the display to that particular file and lists all othe existing .m files.This may be used to provide a default file mane. A wildcard specification such as ' *.m ' lists all the existing MATLAB M-files. Parameter ' dialogTitle ' is a string containing the title of the dialog box. The output variable FILENAME is a string containing the name of the file selected in the dialog box. If the user presses the Cancel butto or if any error occurs,it is set to 0
The output variable FILENAME is a string containing the name of the file selected in the dialog box If the user presses the Concel button or if any error occurs, it is set to O FILENAME, PATHNAME]=UIPUTFILE ('initFile,'dialogTitle,X, Y) places the dialog box at screen position [X, Y] in pixel units Not all systems support this option Example Inewmatfile, newpath=uiputfile(*.mat. 'Save As) See alSo Uigetfile 如果用户选择了已经存在的文件,则出现一个对话窗,询问用户是否要删除存在的文件。如果 回答no,则返回原来的请求程序等待另一次尝试:如果回答yes,则关闭请求程序和对话框并 把文件名返回,文件并未被请求程序删除。如果需要,调用函数必须删除或覆盖文件。 值得牢记的是,这些函数中不论哪一个都未真正地读或写任何文件,调用函数必须做这些 工作。这些函数仅仅是将文件名和路径返回给调用函数。 EMS- Windows和 Macintosh平台上, uisetcolor让用户交互式地选择颜色并选择性地将此颜 色施加到一个对象上。如同 MATLAB42版本, X Window系统平台不支持 uisetcolor uisetcolor的帮助文本是 >>help uisetclor ISETCOLOR Interactively set a ColorSpec by displaying a dialog box C=UISETCOLOR(AI dialogTitle')displays dialog box for the user to fill in, and applies the selected color to the input graphics object The parmeters are option may be specified in any order ARG may be either a handle to a graphics object or an RGB triple If a handle is used, it must specify a graphics object that supports color. If RGB is used, it must be a valid RGB triple(e.g,[100] for red). In both cases, the color specified is used to initialize initializes the color to black itle of the dialog be The output value C is the selected GB triple. If the input parmeter bject 's color is set to the rGb color if RGB triple, if provided: herwise, it is set to o
The output variable FILENAME is a string containing the name of the file selected in the dialog box. If the user presses the Concel button or if any error occurs,it is set to 0. [FILENAME,PATHNAME]=UIPUTFILE ( ' initFile ' , ' dialogTitle ' ,X,Y) places the dialog box at screen position [X,Y] in pixel units. Not all systems support this option. Example: [newmatfile,newpath]=uiputfile ( ' *.mat ' . ' Save As ' ); See also UIGETFILE. 如果用户选择了已经存在的文件,则出现一个对话窗,询问用户是否要删除存在的文件。如果 回答no,则返回原来的请求程序等待另一次尝试;如果回答yes,则关闭请求程序和对话框并 把文件名返回,文件并未被请求程序删除。如果需要,调用函数必须删除或覆盖文件。 值得牢记的是,这些函数中不论哪一个都未真正地读或写任何文件,调用函数必须做这些 工作。这些函数仅仅是将文件名和路径返回给调用函数。 在MS-Windows和Macintosh平台上,uisetcolor让用户交互式地选择颜色并选择性地将此颜 色施加到一个对象上。如同MATLAB4.2C版本,X Window系统平台不支持uisetcolor。 uisetcolor的帮助文本是: >>help uisetclor UISETCOLOR Interactively set a ColorSpec by displaying a dialog box. C=UISETCOLOR(ARG, ' dialogTitle ' ) displays dialog box for the user to fill in,and applies the selected color to the input graphics object. The parmeters are optional and may be specified in any order. ARG may be either a handle to a graphics object or an RGB triple. If a handle is used,it must specify a graphics object that supports color.If RGB is used,it must be a valid RGB triple (e.g.,[1 0 0] for red). In both cases,the color specified is used to initialize initializes the color to black. If parameter ' dialogTitle ' is used, it is a string containing the title of the dialog box. The output value C is the selected GB triple. If the input parmeter is a handle,the graphics object ' s color is set to the RGB color selected. If the user presses Cancel from the dialog box,or if any error occurs,the output value is set to input RGB triple,if provided; otherwise,it is set to 0
ple C=uisetcolor(hText,' Set Text Color) NOTE: This function is only available in MS-Windows and Macintosh versions of matlaB 帮助信息 UISETCOLOR:显示对话框,交互式地设置 Color Space C= UISETCOLOR(ARG,' dialogite')显示一个对话框,让用户输入,并将所选颜色 用于输入的图形对象 参数是可任选,并可以以任何次序指定。 ARG可以是一个图形对象的句柄或是RGB3元组。如果使用句柄,必须指定支持颜色 的图形对象;如果使用RGB,必须是有效的RGB3元组(如:[100是红色)。在这两 种情况下,所指定的颜色用于对话框的初始化。如果没有指定初始的RGB,将对话框 初始化为黑色 如果使用参数 dialog title',该参数是对话框名称的字符串 输出值C是所选的RGB3元组。如果输入参数是句柄,则图形对象的颜色就设定为所 先的颜色。 如果用户揿下对话框中的 Cancel按钮或有错误发生,输出值就设定为输入的RGB3元 组:如果没有输入RGB3元组,则输出值设置为0 例如:c= uisetcoiort( htext,"' settextcoior) 注意:该函数仅在的M- Windous和 Macintosh版本中可用 精通MA∏LAB工具箱具有前面所提及的函数 mmsete。该函数可在所有的平台上工作,功能与 uisetcolor十分相似。 mmsete甚至可允许用户用鼠标来选择颜色并将所选的颜色加到所选择的 对象上。以下就是 mmsete的帮助文本 > help mmsetc MMSETC Obtain an Rgb triple interactively form a color sample MMsetC displays a box for the user to select a color nteractively and displays the resu XMMSETC returns the selected color in x MMSETC ([ g b)) uses the rgb triple as the initial RGB value for modification AMSETC C-or- MMSETC('C)where C is a color spec(y, m,c,r,g, b, w, k),uses the specified color as the initial value MMSETC(H) where the input argument H is the handle of
Example: C=uisetcolor(hText, ' Set Text Color ' ) NOTE:This function is only available in MS-Windows and Macintosh versions of MATLAB. 帮助信息 UISETCOLOR :显示对话框,交互式地设置ColorSpace。 C=UISETCOLOR(ARG, ' dialogtitle ' )显示一个对话框,让用户输入,并将所选颜色 用于输入的图形对象。 参数是可任选,并可以以任何次序指定。 ARG可以是一个图形对象的句柄或是RGB3元组。如果使用句柄,必须指定支持颜色 的图形对象;如果使用RGB,必须是有效的RGB3元组(如:[1 0 0]是红色)。在这两 种情况下,所指定的颜色用于对话框的初始化。如果没有指定初始的RGB,将对话框 初始化为黑色。 如果使用参数 ' dialogTitle ' ,该参数是对话框名称的字符串。 输出值C是所选的RGB3元组。如果输入参数是句柄,则图形对象的颜色就设定为所 选的颜色。 如果用户揿下对话框中的Cancel按钮或有错误发生,输出值就设定为输入的RGB3元 组;如果没有输入RGB3元组,则输出值设置为0。 例如:c=uisetcoior(htext, ' settextcoior ' ) 注意:该函数仅在的MS-Windous和Macintosh版本中可用。 精通MATLAB工具箱具有前面所提及的函数mmsetc。该函数可在所有的平台上工作,功能与 uisetcolor十分相似。mmsetc甚至可允许用户用鼠标来选择颜色并将所选的颜色加到所选择的 对象上。以下就是mmsetc的帮助文本: >> help mmsetc MMSETC Obtain an RGB triple interactively form a color sample. MMSETC displays a box for the user to select a color nteractively and displays the result. X=MMSETC returns the selected color in X. MMSETC ([r g b]) uses the RGB triple as the initial RGB value for modification. MMSETC C -or- MMSETC ( ' C ' ) where C is a color spec (y,m,c,r,g,b,w,k),uses the specified color as the initial value. MMSETC(H) where the input argument H is the handle of
a valid graphics object that supports color, uses the color progerty of the object as the initial RGB value MSETC Select -or MMSTEC('select )waits for the user to click on a valid graphics object that supports color, and uses the color property of the object as the initial rGB value If the initial RGB value was obtained from an object or object handle, the 'Done pushbutton will apply the resulting color property to the selected object If no initial color is specified, black will be used. Examples: mmsetc mycolor=-mmsetc mmsetc(H) mmsetc g mmsetc select mycolor=mmsetc(select ') 下面的例子是利用精通MA∏LAB工具箱中函数mmap和 mmsetc,交互式地使用单色映象: esh(peaks) >>colormap(mmap(mmsetc)) 在MS- Windows和 Machintosh平台上,有最后的请求程序 uisetfont,它让用户可交互式选择字型 属性并将其加于对象上。如同 MATLAB42c版本,ⅹ Window系统平台不支持 uisetfont uisetfont帮助文件是 UISETFONT Interactively set a font by displaying a dialog box H=UISETFONT(HIN, 'dialogTitle' )displays a dialog box for the r to fill in, and applies the selected font to the input graphics object The parmeters are optional and may be specified in any order If parameter HIN is used, it must specity a handle tp a text or axis graphics object. The font properties currently assigned to this object are used to initialize the font dialog box. If parameter ' dialog Title'is used, it is a string containing the title of the dialog box
a valid graphics object that supports color,uses the color progerty of the object as the initial RGB value. MSETC select -or- MMSTEC( ' select ' ) waits for the user to click on a valid graphics object that supports color,and uses the color property of the object as the initial RGB value. If the initial RGB value was obtained from an object or object handle,the ' Done ' pushbutton will apply the resulting color property to the selected object. If no initial color is specified,black will be used. Examples: mmsetc mycolor=mmsetc mmsetc([.25 .62 .54]) mmsetc(H) mmsetc g mmsetc red mmsetc select mycolor=mmsetc( ' select ' ) 下面的例子是利用精通MATLAB工具箱中函数mmap和mmsetc,交互式地使用单色映象: >>mesh(peaks) >>coiormap(mmap(mmsetc)) 在MS-Windows和Machitosh平台上,有最后的请求程序uisetfont,它让用户可交互式选择字型 属性并将其加于对象上。如同MATLAB4.2c版本,X Window系统平台不支持uisetfont 。 uisetfont帮助文件是: >> help uisetfont UISETFONT Interactively set a font by displaying a dialog box. H=UISETFONT(HIN, ' dialogTitle ' ) displays a dialog box for the user to fill in,and applies the selected font to the input graphics object. The parmeters are optional and may be specified in any order. If parameter HIN is used,it must specity a handle tp a text or axis graphics object. The font properties currently assigned to this object are used to initialize the font dialog box. If parameter ' dialogTitle ' is used,it is a string containing the title of the dialog box