Matlab-时钟绘制资料_第1页
Matlab-时钟绘制资料_第2页
Matlab-时钟绘制资料_第3页
Matlab-时钟绘制资料_第4页
Matlab-时钟绘制资料_第5页
已阅读5页,还剩7页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Mat l ab- 时 钟 绘 制精品文档一题目请用 Matlab 编写程序,绘制一个时钟表盘和时针、分针、秒针,且时钟能根据计算机系统当 前时间,自动更新时针、分针、秒针的位置。表盘和时针、分针、秒针使用 plot 函数绘制,计算 机系统当前时间使用 clock 函数获取。二操作方法与实验步骤(一) 总体设计思想 设计时钟,根据适中的样式先画出表盘,根据数学公式画出时分刻度以及时针分针,再根 据 clock 函数读取计算机当前时间,最后加上循环语句让时钟走起来。(二) 所用到的数学公式1. 绘制表盘(圆): x = cos (theta1); y = sin (theta1);2. 绘制时分

2、刻度:Plot ( 0.9*cos (theta3(i) ), 0.97*cos(theta3(i) ) ,0.9*sin (theta3(i) ),0.97*sin( theta3(i) ) );3. 绘制时针分针:theta_h=0.5 * pi-(h+m/60)/12*2*pi;plot ( 0,0.6 * cos(theta_h), 0,0.6*sin(theta_h),blue ,linewidth , 2);theta_m=0.5*pi-m/60*2*pi;plot (0,0.7*cos(theta_m),0,0.7*sin(theta_m), cyan , linewidth ,

3、 2); theta_s=0.5*pi-(s/60)*2*pi;plot (0,0.85*cos(theta_s),0,0.85*sin(theta_s), black , linewidth , 2)4. clock 读取计算机当前时间: C=clock; h=C(4); m=C(5); s=C(6);三) 程序流程图用极坐标与直角坐标的关系绘制圆盘:theta1=0:2*pi/100:2*pi;x=cos(theta1);y=sin(theta1);精品文档精品文档绘制分刻度线:plot(0.9*cos(theta3(i),0.97*cos(theta3(i),0.9*sin(theta3

4、(i),0.97*sin(theta3(i)j +读取计算机当前时间并画出时分秒针:C=clock; h=C(4); m=C(5); s=C(6); theta_h=0.5*pi-(h+m/60)/12*2*pi; plot(0,0.6*cos(theta_h),0,0.6*sin(theta_h),blue ,linewidth,2);theta_m=0.5*pi-m/60*2*pi;plot(0,0.7*cos(theta_m),0,0.7*sin(theta_m),cyan ,linewidth,2);theta_s=0.5*pi-(s/60)*2*pi;plot(0,0.85*cos(

5、theta_s),0,0.85*sin(theta_s),black, linewidth,2);加上循环使表走起来: while四) 实验代码收集于网络,如有侵权请联系管理员删除精品文档1. 利用极坐标与直角坐标的关系绘制圆theta1=0:2*pi/100:2*pi;x=cos(theta1);y=sin(theta1);h=plot(x,y);% 绘制圆set(h,linewidth,6) % 设置圆的属性holdon% 保留已经绘制的图形axisequal% 是横纵坐标系的单位长度相同2. 绘制时刻度线与分刻度线theta2=0:2*pi/12:2*pi;fori=1:length(t

6、heta2) % 循环语句绘制时刻度线 h=plot(0.8*cos(theta2(i),0.97*cos(theta2(i),0.8*sin(theta2(i),0.97*sin(theta2(i);set(h,linewidth ,3)set(h,color , black )endtheta3=0:2*pi/60:2*pi;fori=1:length(theta3) % 循 环 语 句 绘 制 分 刻 度 线 h=plot(0.9*cos(theta3(i),0.97*cos(theta3(i),0.9*sin(theta3(i),0.97*sin(theta3(i);set(h,col

7、or , black )e nd收集于网络,如有侵权请联系管理员删除精品文档3. 绘制时针分针并读取计算机当前时间C=clock; % 调用 clock 函数读取当前时间h=C(4); % clock 函数: year month day hour minute seconds 4 代表, 5 ,6 分别m=C(5); 时分秒s=C(6);theta_h=0.5*pi-(h+m/60)/12*2*pi;plot(0,0.6*cos(theta_h),0,0.6*sin(theta_h),blue ,linewidth,2);theta_m=0.5*pi-m/60*2*pi;plot(0,0.7

8、*cos(theta_m),0,0.7*sin(theta_m),cyan ,linewidth,2);theta_s=0.5*pi-(s/60)*2*pi;plot(0,0.85*cos(theta_s),0,0.85*sin(theta_s),black, linewidth,2);收集于网络,如有侵权请联系管理员删除精品文档4. 让时钟走起来完成实验while (1)theta1=0:2*pi/100:2*pi;X=cos(theta1);y=sin(theta1);h=plot(x,y);set(h, linewidth ,6)hold onaxis equalplot(0,0, .

9、, Markersize ,50); theta2=0:2*pi/12:2*pi;for i=1:length(theta2) h=plot(0.8*cos(theta2(i),0.97*cos(theta2(i),0.8*sin(theta2(i), 0.97*sin(theta2(i);set(h, linewidth ,3)set(h, color , black )end theta3=0:2*pi/60:2*pi;for i=1:length(theta3) h=plot(0.9*cos(theta3(i),0.97*cos(theta3(i),0.9*sin(theta3(i),0

10、.97*sin(theta3(i);set(h, color , black )endC=clock;h=C(4);m=C(5);s=C(6);theta_h=0.5*pi-(h+m/60)/12*2*pi; plot(0,0.6*cos(theta_h),0,0.6*sin(theta_h), theta_m=0.5*pi-m/60*2*pi;plot(0,0.7*cos(theta_m),0,0.7*sin(theta_m), theta_s=0.5*pi-(s/60)*2*pi;plot(0,0.85*cos(theta_s),0,0.85*sin(theta_s), pause(1);clf; % 清除上一步的图像blue , linewidth

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论