ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:28.49KB ,
资源ID:4926568      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4926568.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(GUI图形用户界面入门4.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

GUI图形用户界面入门4.docx

1、GUI图形用户界面入门4GUI图形用户界面入门(4)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 u

2、sing 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 lin

3、ewidth 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_EVALif nargin=0 arg1=

4、 color ;arg2= w ;arg3= style ;arg4= : ;nargin=4;endif 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 ,

5、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 p

6、oint set(gca, Userdata ,fp(1,1:2) %store in axes userdata 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

7、 , 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 handleelseif arg1=3 % callback is line end point,finish up set(gcf, Point , arrow,. BackingStore , on ,. WindowButtonDownFcn , ,. Wind

8、owButtonMotionFcn , 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

9、%.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(

10、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文件。比较这两个文件,可以了解到,为实现各种GUI M文件要做出一些折衷。21.9 对话框和请求程序MATLA

11、B具有建立对话框和 请求 的几个有用工具。对话框是弹出显示的单独窗口,它显示信息字符串。对话框含有一个或多个按钮键以供用户输入。请求框是在弹出显示的单独窗口,利用鼠标或键盘获得输入,并返回信息给调用函数。对话框所有MATLAB的对话框都是基于函数dialog,它的帮助文本如下help diologDIALOG displays a dialog box.FIG = DIALOG (pl ,vl.)displays a dialog box.valid param/value pairs includeStyle error | warning | help | questionName str

12、ingReplace on | offResize on | offBackgroundColor ColorSpecButtonString Button1String | Button2String | . ButtonCalls ButtonCallback | Button2Callback | . ForegroundColor ColorSpecPosition x y width height x y - centers around screen pointTextString stringUnits pixels | normal | cent | inches | poin

13、tsUserData matrixNote: Until dialog becomes built-in, set and getare not valid for dialong objects.At most three buttons are allowed.The callbacks are ignored forquestiondialogs.If ButtonStrings /ButtonCalls are unspecified then itdefaults to a single ok button which removes the figure.There s still

14、 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可能成为具有更多功能的内置函数。缺省的对话框是一个帮助对话框,它是由 Def

15、ault help string 字符串和标有 OK 的按钮键组成的编辑文本框。作为例子,键入 dialog。预先定义的对话框是由函数helpdlg,enordlg,warndlg和gucstdlg建立。helpdlg和warndlg接受文本字符串和窗口标题字符串作为输入参量。errordlg接收 Replace 变量作为输入。除了questdlg,所有上述函数都产生类似的对话框,它有各自缺省的标题和文本字符串。标有 OK 的单个按钮,则关闭对话框。helpdlg帮助文本是: help helpdlgHELPDLG: Displays a help dialog box. HANDLE=HEL

16、PDLG(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的帮助信息hel

17、pstring。如果名为dlgname的帮助对话框已在屏幕上显示,则引到屏幕正面,否则就建立该帮助对话框。参阅:dialogwarndlg的帮助文本是:help warndlgWARNDLG 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

18、disappear. See also:DIALOGerrordlg的帮助文本是help errordlgERRORDLG Creates an error dialog boxHANDLE = 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 a

19、nd an error dialog with Name DLGNAME already exits,it is simply brought to the front (no new dialog is created). See also :DIALOG帮助信息ERRORDLG:建立出错对话框HANDLE=ERRORDLG(ERRORSTR,DLGNAME,REPLACE)建立显示出错信息errorstr、名为dlgname的出错对话框,要消除出错信息对话框,必须揿下标记为OK的按钮,如果replace= on 并且名为digname的出错对话框已经存在,则就引到屏幕正面,不再建立新的对话

20、框。参阅:dialog提问的对话框稍有不同,前三种函数只显示一个按钮键并返回对话框图形对象的句柄。函数questdlg显示两个或三个按钮键,返回由用户所选的按钮的标志字符串。questdlg的帮助文本如下:help qeustdlgQEUSTDLG Creates a question dialog box.CLICK=QUESTDLG(Q,YES,O,CANCEL,DEFAULT) creates a questiondialog box which displays Q.Up to three pushbuttons,with strings given by YES,NO,and CAN

21、CEL,will appearalong with Q in the dialog.The dialog wil be destroyedreturning the string CLICK depending on which button isclicked.DEFAULT is the default button number.帮助信息QUESTDLG:建立问题对话框CLICK=QVESTDLG(Q,YES,NO,CANCEL,DEFAULT)建立显示信息Q的问题对话框。至多有三个按钮具有由YES,NO和CANCEL给定的字符串,按钮与Q一起,显示在对话框中。根据所击的按钮返回字符串C

22、LICK对话框消失。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 y

23、our mind. question1, Yes , No ); if stromp (response2, Yes ) colormap(copper); end end请求程序请求程序通过对话框获取用户的输入。请求程序是内置式GUI函数,它使用平台原有的窗口系统建立外观熟悉的请求程序。函数uigecfile和uiputfile是所有平台上都有的内置式函数,用于交互地获得文件名,从而调用函数用它读取文件中数据或将数据存于文件中。uigetfile的帮助文本是:help uigetfileUIGETFILE Interactively retrieve a filename by displa

24、ying a dialog box.FILENAME,PATHNAME=UIGETFILE( filterSpec , dialogTitle ,X,Y)displays a dialog box for the user to fill in,and returns thefilename 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 cont

25、rol 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 previousparameters must also be used.The felterSpec parameter determines the initial display of files inthe dialog box.For example *.m lists all the MA

26、TLAB M-files.Parameter dialogTitle is a string containing the title of the dialogbox.The X and Y parameters define the initial position of the dialogbox in units of pixels. Some systems may not support this option.The output variable FILENAME is a string containing the mane of thefile selected in th

27、e dialog box.If the user presses the Cancel buttonor 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:通

28、过显示对话框交互式地检索文件名FILENAME,ATHNAME=UIGETFILE( filterspec , dialogtitle ,x,y)显示一个对话框,让用户输入,并返回路径和文件名字符串。仅当文件存在时,才成功地返回。如果用户选择了一个并不存在的文件,就显示出错信息,控制框返回到对话框。用户可以输入另一个文件名或揿下Cancel按钮。所有输入参数都是可任选的,如果用其中之一个,也必须使用所有先前参数。参数filteospec决定对话框中文件的初始显示。例如 *.m 列出的所有M文件。参数 dialogtitle 是对话框标题字符串。以象素为单位参数x,y定义对话框的初始位置,有些系

29、统可能不支持这个选项。输出变量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

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1