




已阅读5页,还剩31页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
MATLAB程序设计基础 图形用户界面编程 MATLAB图形界面中各对象关系 根对象root 图形窗口对象figure 右键菜单对象uicontextmenu 菜单对象uimenu 控件对象uicontrol 坐标轴对象axes 线对象line 文字对象text 表面图对象surface 图像对象image 光源对象light 窗口对象及其属性设定 窗口对象的建立hwin figure 属性1 属性值1 属性2 属性值2 hwin为图形窗口的句柄 matlab环境允许打开多个窗口 每个窗口都对应自己的句柄 通过该句柄可以进一步对窗口的属性等进行操作 hwin gcf获得当前窗口的句柄 图形窗口的属性 常用属性color属性由红绿蓝三原色组成 取值范围为0到1 menubar属性设置菜单条的形式 name属性设置图形窗口的标题栏中标题内容 其属性值为一字符串 numbertitle属性是否显示图形窗口标题栏中的图形标号 units属性设定图形单位 如 pixels 象素点 inches 英寸 centimeters 厘米 normalized 归一值 等 position属性设定窗口的位置和大小 为1 4向量 前两个值为窗口左下角横纵坐标值 后两个元素值为窗口的宽度和高度 其单位由units属性设定 resize属性确定是否可以改变图形窗口的大小 toolbar属性是否显示工具条 visible属性决定窗口是否为可见 Pointer属性设置鼠标的显示形式 对象属性的修改 改变对象的属性值set 对象句柄 属性1 属性值1 属性2 属性值2 属性的名称用单引号括起来 如果不给出属性值 则返回全部允许的属性值 获得对象的属性值V get 句柄名 属性 gwin figure visible off set gwin color 1 0 0 position 100 200 300 300 name Myprogram numbertitle off menubar none set gwin visible on 回调函数 callbackfunction CloseRequestFcn 关闭窗口时响应函数KeyPressFcn 键盘按下时响应函数windowButtonDownFcn 鼠标按下时响应函数WindowButtonMotionFcn 鼠标移动时响应函数CreateFcn和DeleteFcn 建立和删除对象时响应函数CallBack 对象被选中时响应函数 gwin figuregwin 1 set gwin windowbuttondownfcn helpdlg mousebuttondown set gwin keypressfcn helpdlg keyboardpressed 一旦该对象指定的事件发生 将自动调用某指定的函数 它可以是matlab文件 也可以是一组matlab程序 标准对话框及其调用 文件名操作函数uigetfile 和uiputfile 函数打开一个文件进行读 写的对话框 fname pname uigetfile ffilter strtitle x y ffilter为文件名过滤器 strtiltle为对话框窗口标题栏的显示内容 x y为对话框出现的位置 省略则采用默认位置 f p uigetfile m txt 请选择一个文件 f fileprint mp E MATLABR11 work 颜色设置对话框c uisetcolor 或c uisetcolor c0 函数返回一个1 3的颜色向量 分别对应红 绿 蓝三原色 按下 取消 按钮后返回空的向量 如果给出向量c0 则在图中指向c0所定义的颜色位置 且按下 取消 按钮时返回c0的值 字体设置对话框h Font uisetfont或h Font uisetfont h Text strTitle h Font为字体属性的结构体 h Text为要设置的字符句柄 strTitle为对话框的标题栏内容 s uisetfonts FontName 楷体 GB2312 FontUnits points FontSize 42FontWeight bold FontAngle normal 警告与错误信息对话框warndlg和errordlg函数二者的显示图标不同 例 h warndlg error code1111 Warning h errordlg error code1111 Error 帮助信息对话框与警告 错误信息对话框基本一致 仅仅是图标的不同 例 h helpdlg 帮助信息 帮助信息对话框和警告错误对话框基本一致 只是图标不同 帮助 通用信息框msgbox 显示信息 标题 图标 图标包括 Error Help Warn以及Custom 如果缺省则为None data 1 64 data data data 64 msgbox Thisisanexampleofmsgbox customico custom data hot 64 Matlab图形界面基本控件 静态文本 text 一般用来作为信息提示用 编辑框 edit 读取用户数据的文字窗口 框架 frame 概括一组控件 也可以修饰用 列表框 list 包含多个选项供用户选择 滚动条 slider 图示某个范围 按钮 pushbutton 其上的字符说明其作用 切换按钮 toggle 两状态按钮 单击改变其状态 收音机按钮 radio 一组选项 其中只能有一个被选中 检取框 check 一组选项 可以选择多项 弹出式菜单 popup 选中时打开一个列表 控件的常用属性 Units与position属性意义同上 这里的位置是相对该窗口的左下角 String属性标注在控件上 用来说明或提示 Callback属性实现该控件的实质性功能 Enable属性该控件的使能状态 on 或 off Cdata属性真彩色位图 为一三维数组 用于美化界面 Tooltipstring属性鼠标指针位于该控件时的提示信息显示 Interruptable属性是否中断当前回调函数的执行 on 或 off 字体属性设置字体 例1 h main figure name ademoofguidesign menubar none numbertitle off position 100100300100 h edit uicontrol style edit backgroundcolor 111 position 20205020 tag myedit string 1 horizontalalignment left h but1 uicontrol style pushbutton position 20505020 string INC callback v eval get h edit string set h edit string int2str v 1 h but2 uicontrol style pushbutton position 80505020 string DEC callback v eval get h edit string set h edit string int2str v 1 functiongui counter1 gui counterisademoofguidesign h main figure name ademoofguidesign menubar none numbertitle off position 100100300100 h edit uicontrol style edit backgroundcolor 111 position 20205020 tag myedit string 1 horizontalalignment left h but1 uicontrol style pushbutton position 20505020 string INC callback h findobj gcf tag myedit v eval get h string set h string int2str v 1 h but2 uicontrol style pushbutton position 80505020 string DEC callback h findobj gcf tag myedit v eval get h string set h string int2str v 1 例2 functiongui demo GUI demoisanotherdemoofGUIdesign h main figure units normalized position 0 30 30 50 4 name GUIdemostration numbertitle off h axis axes units normalized position 0 30 150 60 7 tag axplot xlim 010 ylim 11 t 0 0 1 10 y sin t line t y bmp1 imread 1 bmp bmp2 imread 2 bmp bmp3 imread 3 bmp bmp4 imread 4 bmp h 1 uicontrol style pushbutton units normalized position 0 10 60 060 1 cdata bmp1 callback zoomon tooltipstring Enablezooming h 2 uicontrol style pushbutton units normalized position 0 040 450 060 1 cdata bmp2 callback zoomxon tooltipstring Enablezoomonx axisonly h 3 uicontrol style pushbutton units normalized position 0 160 450 060 1 cdata bmp3 callback zoomyon tooltipstring Enablezoomony axisonly h 4 uicontrol style pushbutton units normalized position 0 10 30 060 1 cdata bmp4 callback zoomoff tooltipstring Disablezooming Matlab菜单系统设计 菜单系统的生成菜单项句柄 uimenu 窗口句柄 属性1 属性值1 属性2 属性值2 子菜单句柄 uimenu 菜单项句柄 属性1 属性值1 属性 菜单条名称label回调函数callback 热键名称accelerator背景颜色backgroundcolor前景颜色foregroundcolor选中状态checked使能状态enabled菜单条位置position分隔符separator ctxmenu uicontextmenu set gcf uicontextmenu ctxmenu uimenu ctxmenu label zoomon callback zoomon uimenu ctxmenu label x axiszoomon callback zoomxon uimenu ctxmenu label y axiszoomon callback zoomyon uimenu ctxmenu label zoomoff callback zoomoff uimenu ctxmenu label checked checked on separator on uimenu ctxmenu label disabled enable off GUI设计工具简介 guideGUI向导设计器 属性设计器 PropertyEditor 设置所选图形对象或GUI控件各属性的值 控件布局编辑器 AlignmentTool 设置控件的布局 菜单编辑器 MenuEditor 编辑菜单项 回调函数编辑器 CallbackEditor 编辑控件属性所对应的回调函数 例 示意小球碰撞过程 出射角 上挡板 下挡板 h1 line 0 1 0 09 11 set h1 linewidth 5 h2 line 0 1 1 09 11 set h2 linewidth 7 uu 010 0 050 5 set h main userdata uu Tag lstcolor Tag rdradio1 Tag rdradio2 Tag rdradio3 functionexec bouncing x k 1 uu get gcf userdata ifnargin 0 x y k ginput 1 uu 3 x set gcf userdata uu endifk 1ifx1 x 1 endxx 0 yy 1 x0 0 x1 x y1 1 while x1 1 x xx xxx1 y1 y1 yy yyy1 x0 x1 x1 x1 x enddx 1 50 xx l 0 dx 1 xx xx l sort xx
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 监事聘任与公司内部控制与合规风险防范合同范本
- 离职员工知识产权转让与保密协议书
- 知识产权保护与保密协议范本(适用于动漫产业)
- 上市公司高管离职补偿金及离职后竞业限制协议
- 离婚申请书模板及子女抚养权及赡养费支付合同
- 数字化转型对区域经济发展协调性的作用
- 2025年烧结理论考试试题及答案
- 电炉炉前工考试题及答案
- 西双版纳活动拓展策划方案
- 2025年五级下册数学的试卷及答案
- 某水库调度规程完整
- Cpk 计算标准模板
- 封起DE日子博文 2006
- 锂离子电池生产安全讲座
- 画魂空手套无删减全文下载
- 五猖会原文 五猖会
- 主题教育苏轼生平介绍人物经历等PPT模板(内容完整)
- 眼科学-眼科检查(课件)
- 产品碳足迹课件
- 美国地图高清中文版
- 监控中心值班人员绩效考核月度考核表
评论
0/150
提交评论