




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 程序 主程序主程序 时钟程序时钟程序 clock1 m 注意使用原始文件名注意使用原始文件名 function clock1 try close all create the figure h0 figure MenuBar none Color white NumberTitle off Name Clock 背景程序 不用可以删 ha axes units normalized position 0 0 1 1 uistack ha down II imread 3 jpg 3 jpg 是图片地址 image II colormap gray set ha handlevisibility off visible off create a menu to set the timing clock regular t uimenu Parent h0 Label 闹钟 Callback timing 调用了 timing m create a menu to calculate the time cal t uimenu Parent h0 Label 计时 Callback run calc time 运行了 calc time m 文件 theta linspace 0 6 288 1000 6 28 近似等于 2 pi x1 8 cos theta y1 8 sin theta plot x1 y1 color 0 5 0 5 0 5 linewidth 16 时钟的外 层 hold on 2 axis equal fill x1 y1 0 7 0 7 0 7 时钟的内层 text 0 5 the big bag fontsize 16 color 0 8 0 8 0 8 HorizontalAlignment center the name of the clock lighting phong material metal axis off axis 10 10 10 10 set gca position 0 1 0 1 0 775 0 815 t title floor clock title num2str t title 1 年 num2str t title 2 月 num2str t title 3 日 fontname Verdana fontsize 13 color 0 2 0 2 0 2 创建一个 edit 控件去显示数字时间 h0 edit uicontrol parent h0 a edit to show the hour minute second dymaically enable inactive BackgroundColor 1 0 8 0 4 fontname Verdana fontsize 12 style edit horizontal center units normalized position 0 38 0 04 0 22 0 08 string num2str t title 4 num2str t title 5 num2str t title 6 for k 1 12 xk 8 8 cos 2 pi 12 k pi 2 yk 8 8 sin 2 pi 12 k pi 2 plot xk 9 8 xk 9 7 yk 9 8 yk 9 7 color 0 8 0 8 0 8 linewidth 3 text xk yk num2str k fontsize 16 color 0 9 0 3 0 8 HorizontalAlignment center mark of clock 3 end ti clock get the current time 时针初始位置 th out ti 4 ti 5 60 ti 6 3600 12 2 pi pi 2 the angle of clock is different from the axes so pi 2 is needed to correct th in th out pi hh plot 1 5 cos th in 5 cos th out 1 5 sin th in 5 sin th out color 0 8 0 8 0 8 linewidth 9 分针初始位置 tm out ti 5 ti 6 60 60 2 pi pi 2 tm in tm out pi hm plot 2 cos tm in 6 cos tm out 2 sin tm in 6 sin tm out color 0 8 0 8 0 8 linewidth 7 秒针初始位置 ts out ti 6 60 2 pi pi 2 ts in ts out pi hs plot 3 cos ts in 7 cos ts out 3 sin ts in 7 sin ts out color 0 8 0 8 0 8 linewidth 4 fill 0 2 cos theta 0 2 sin theta w the center crew of the clock set gcf doublebuffer on flag 3 while ishandle h0 请不要使用 1 来无限循环 ti floor clock get the current time from loop str num2str ti 4 num2str ti 5 num2str ti 6 set h0 edit String str use the edit to show the current time 4 calculate the next position of pointer of hour th out ti 4 ti 5 60 ti 6 3600 12 2 pi pi 2 th in th out pi set hh XData 1 5 cos th in 5 cos th out YData 1 5 sin th in 5 sin th out calculate the next position of pointer of minute tm out ti 5 ti 6 60 60 2 pi pi 2 tm in tm out pi set hm XData 2 cos tm in 6 cos tm out YData 2 sin tm in 6 sin tm out calculate the next position of pointer of second ts out ti 6 60 2 pi pi 2 ts in ts out pi set hs XData 3 cos ts in 7 cos ts out YData 3 sin ts in 7 sin ts out light position 10 15 0 style local color 0 8 0 3 0 3 drawnow pause 0 09 end catch error please mail to 1917066897 return end end 子程序一子程序一 闹钟程序闹钟程序 timing m 注意使用原始文件名注意使用原始文件名 5 function timing obj event save the current time ti clock create a input dialog prompt mouth day hour minute event title input your timing clock time answer inputdlg prompt title disp answer test code get the time form client time set clock time set 2 str2num answer 1 time set 3 str2num answer 2 time set 4 str2num answer 3 time set 5 str2num answer 4 time set 6 0 T event 1 1 answer 5 disp time set test code show your set time str 你在 num2str time set 1 answer 1 answer 2 answer 3 answer 4 设置了一个闹钟 内容为 answer 5 disp str test code msgbox str attention create a timer h timing timer Name H timing TimerFcn T ring T event 调用了 T ring m 并传参 ExecutionMode singleShot start the timer startat h timing time set end 子程序一子程序一 铃声程序铃声程序 6 T ring m 注意使用原始文件名注意使用原始文件名 function T ring obj event T event UNTITLED Summary of this function goes here Detailed explanation goes here save the content of cell T event msg T event 1 1 disp msg test code msgbox msg 你有一个闹铃提醒 这是 matlab 自带的铃声 其他的铃声程序可以在网上找 for i 1 5 load splat sound y Fs end end 子文件子文件 计时程序 注 这不是一个函数文件 计时程序 注 这不是一个函数文件 calc time m 注意使用原始文件名注意使用原始文件名 create a figure h1 figure MenuBar none Color white NumberTitle off units normalized position 0 35 0 4 0 3 0 2 Name Calc time h1 text uicontrol parent h1 BackgroundColor 1 0 8 0 4 fontname Verdana fontsize 20 style text horizontal center units normalized position 0 15 0 5 0 7 0 3 string 0 0 0 0 h1 button start uicontrol parent h1 7 BackgroundColor 1 0 8 0 4 fontname Verdana fontsize 12 style pushbutton horizontal center units normalized position 0 15 0 2 0 2 0 2 callback k 0 string start h1 button stop uicontrol parent h1 BackgroundColor 1 0 8 0 4 fontname Verdana fontsize 12 horizontal center units normalized position 0 40 0 2 0 2 0 2 callback k 1 string stop h1 button reset uicontrol parent h1 BackgroundColor 1 0 8 0 4 fontname Verdana fontsize 12 horizontal center units normalized position 0 65 0 2 0 2 0 2 callback k 2 string reset k 2 while ishandle h1 if 0 k t that clock while ishandle h1 t this clock 8 if t this 6 t that 6 t second t this 6 t that 6 else if t this 5 t that 5 t this 5 t this 5 1 t second t this 6 60 t that 6 else t this 4 t this 4 1 t this 5 t this 5 59 t second t this 6 60 t that 6 end end if t this 5 t that 5 t minute t this 5 t that 5 else t this 4 t this 4 1 t minute t this 5 60 t that 5 end t hour t this 4 t that 4 set h1 text String num2str t hour num2str t minute num2str t second pause 0 1 important pause in inside while if k 1 break end if k 2 set h1 text String 0 0 0 0 break end end close inside while 9 end if k 2 set h1 text String 0 0 0 0 end pause 0 1 important pause in outside while end close outside while 摘要 使用 matlan 的画图函数 如 plot fill 等 设计了一个简约的圆形时钟 GUI 并使用图形句柄实现了动态显示时间 自带图像背景 具有闹钟功能 关键词关键词 matlab 时钟 matlab 闹钟 clock timer matlab GUI 背景 matlab 计时 1 工具与函数 MATLAB MATLAB 是 matrix 创建一个图形窗口 所有属性皆为默认 figure 属性 属性值 创建一个用户自定义的图形窗口 h figure 属性 属性值 创建一个图形窗口 并返回窗口的句柄 uicontrol Uicontrol 是 user interface control 的缩写 用户界面控制 MATLAB 控制框 又 称 uicontrol 与窗口管理器所用的函数十分相似 它们是图形对象 可以放置在 MATLAB 的图形窗中的任何位置并用鼠标激活 MATLAB 的 uicontrol 包括按钮 滑 标 文本框及 弹出式菜单 语法 H uicontrol Hf fig 属性 属性值 其中 H 是由函数 uicontrol 生成 uicontrol 对象的句柄 Hf fig 是父对象的句柄 它必须是图形 属性 Style 决定了所建控制框的类型 Callback 属性值是当控 制框激活时 传给 eval 在命令窗口空间执行的 MATLAB 字符串 timer 鉴于 Matlab 中缺乏多线程机制 使用 Timer 无疑是一个很重要的工具 Matlab 中 Timer 定时器 是一个 Java 对象 语法 t timer 属性 属性值 属性 TimerFcn Timer 执行的函数 属性值 function name 就是你定义的 函数名 ExecutionMode 执行模式 决定定时器对象如何安排定时事件 属性值 singleShot 默认值 fixedDelay fixedRate fixedSpacing Period 定时器触发周期 默认值为 1s 数据类型 double 最小定时时长 0 001 StartDelay 指定从定时器开始到第一次执行 callback 函数的延时时长 数据类型 double 值的范围 大于 0 的数 默认值为 0 即若加此属性 第一次定时时间为 Period StartDelay StartFcn 定时器开启时的回调函数 StopFcn 定时器停止时的回调函数 startat OBJ Y M D H MI S 在 Y M D H MI S 时间上启动 timer Y 年 M 月 D 日 H 时 MI 分 S 秒 11 2 设计思路 2 1 创建时钟的外层 我做的是一个典型的时钟 采用的圆形的外表 实现 圆形外表 可以使用画图函数 如 plot ezplot fplot 等函数画圆 颜色填充 然后直接线条属性定义 加大其线条宽度 以及设置相应的颜色 2 2 时钟的时针 分针 秒针 指针的外形 指针的外形 采用的是条形 矩形 的指针 时针角度 使用 clock 获得当前时间 计算当前的时间的小时 t 除以 12 获得所 转过角度的百分比 再乘以 2 pi 得到时针转过的角度 但是 时针转过的角度 是 从时钟 12 点 位置顺时针开始算的 和我们使用 x 轴 即时钟 3 点 位置 逆时 针的计算方法有差别 所以需要矫正 对求出来的时针转过的角度去相反数 在加上 pi 2 就可以实现从时钟 12 位顺时计算 转换到时钟 3 点 逆时计算 时针角度 同理 使用 clock 获得当前时间 计算当前的时间的分钟 t 除以 60 获得所转过角度的百分比 再乘以 2 pi 得到分针转过的角度 但是 分针转过的角 度 是从分针 12 点 位置顺时针开始算的 和我们使用 x 轴 即时钟 3 点 位置 逆时针的计算方法有差别 所以需要矫正 对求出来的分针转过的角度去相反数 在 加上 pi 2 就可以实现从时钟 12 位顺时计算 转换到时钟 3 点 逆时计算 时针角度 使用 clock 获得当前时间 计算当前的时间的秒数 t 除以 60 获得所 转过角度的百分比 再乘以 2 pi 得到秒针转过的角度 但是 秒针转过的角度 是 从时钟 12 点 位置顺时针开始算的 和我们使用 x 轴 即时钟 3 点 位置 逆时 针的计算方法有差别 所以需要矫正 对求出来的秒针转过的角度去相
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乡村建筑销售合同范本
- 平塘买房合同范本
- 出租 续签合同范本
- 供货的制式合同范本
- 简易雇保安合同范本
- 胶纸打包出售合同范本
- 小区房产转让合同范本
- 换热器维修合同范本
- 终止提供服务合同范本
- 冷柜仓库转让合同范本
- 屏幕尺寸换算表
- 金属技术监督管理制度
- 建筑行业材料员培训课件
- 佐贺的超级阿嬷亲子阅读单
- 企业工会制度大全
- NB-T 10316-2019 风电场动态无功补偿装置并网性能测试规范
- JJF(纺织)010-2012纱线捻度仪校准规范
- GB/T 16288-2008塑料制品的标志
- GB/T 14486-2008塑料模塑件尺寸公差
- 第三单元名著导读《朝花夕拾-二十四孝图》课件(15张PPT) 部编版语文七年级上册
- 口部运动功能评估分级标准
评论
0/150
提交评论