et(gco,Ur HorizontalAlignment','left mmdraw是精通 MATLAB工具箱中另一个有用GU函数,它与 mmtext十分相似,但更为复杂, 此函数允许用户用鼠标在当前的坐标轴上画线并设置线的属性 function mmdraw(argl, arg2, arg3, arg4 arg6, arg7) %MMDRAW Draw a Line and Set Propertie %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 %Pro %NAME VaLUe(defult %color ly m biw) k]or an rgb in quotes: '[rg b] %style ---:}- %omark %width points for linewidth 10.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'[150 set color to orange o Copyright (c)1996 by Prentice-Hall, Inc global MMDRAW HI MMDRAW EVAL argl=color: arg2=w: arg3=style: arg4=: if isst(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 ButtonMotion Fcn draw(2) Window ButtonUpFcn aw(3)") elseif argl=2 callback is mouse motion cp=get(gca, CurrentPoint'): cp=cp(1, 1: 2) fp=get(gca, 'Userdata): HI=line( Xdata, [fp(1): cp(1)), ' 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 arg l=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 EVAL MMDRAW EVAL=D: name=eval(sprintf('arg%of, 1), ) get name argument al(sprintf(arg%.of', i+1) 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 MMDRAW HL=O
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 Button String ButtonI String I Button2String I Button Calls Button Callback Button2 Callback I ForegroundColor Position [x y width height x y- centers around screen point TextString string tels normal I cent I inches I User Data matrIx Until dial are not valid for dalong objects At most three buttons are allowed The callbacks are ignored for"question"dialogs If ButtonStrings/Button Calls are unspecified then it defaults to a single"ok"button which removes the figure Theres 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 withQ in the dialog. The dialog wil be destroyed turning the string click depending on which button is clicked DEfAULT is the default button numb 帮助信息 QUESTDLG:建立问题对话框 CLCK= QVESTDLG(O,YES,NO, CANCEL, DEFAULT建立显示信息Q的问题对 话框。至多有三个按钮具有由YES,NO和 CANCEL给定的字符串,按钮与Q一起,显 示在对话框中。根据所击的按钮返回字符串 CLICK对话框消失。 DEFAULT是缺省的 按钮数。 下面是函数的片断,说明了函数中提问对话框的应用: questionI=Change color map to copper? response=questdlg(question1, 'Sure ope,' Maybe, 2): if stroma(respo colormap(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 请求程序