matlab时钟程序

上传人:汽*** 文档编号:495406553 上传时间:2024-01-01 格式:DOC 页数:7 大小:58KB
返回 下载 相关 举报
matlab时钟程序_第1页
第1页 / 共7页
matlab时钟程序_第2页
第2页 / 共7页
matlab时钟程序_第3页
第3页 / 共7页
matlab时钟程序_第4页
第4页 / 共7页
matlab时钟程序_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《matlab时钟程序》由会员分享,可在线阅读,更多相关《matlab时钟程序(7页珍藏版)》请在金锄头文库上搜索。

1、% fill(6,7,7,6,5,5,0,0,0,0.5,0);%右边竖条的填充% hold on; %保持当前图形及轴系的所有特性% fill(2,6,6,2,3,3,0,0,0,0.5,0);%左边竖条的填充% hold on;% 保持当前图形及轴系的所有特性% t1=0:pi/60:pi;% plot(4-2*sin(t1-pi/2),5-2*cos(t1-pi/2);%绘制中间的凹弧图形% grid;%添加网格线% axis(0,9,0,9);%定义坐标轴的比例% %axis(off);%关闭所有轴标注,标记,背景% fill(1,2,2,1,5,5,0,0,0,0.5,0);%中间长

2、方形的填充% hold on;% 保持当前图形及轴系的所有特性% title(31608118);%定义图题% x0=6;% y0=5;% head1=line(x0,y0,color,r,linestyle,.,erasemode,xor,markersize,30);% head2=line(x0,y0,color,r,linestyle,.,erasemode,xor,markersize,50); %设置小球颜色,大小,线条的擦拭方式% t=0;%设置小球的初始值推荐精选% dt=0.001;%设置运动周期% t1=0;%设置大球的初始值% dt1=0.001;% while 1%条件

3、表达式% t=t+dt;% x1=9-1*t;% y1=5;% x3=6;% y3=5;% if t0% x2=6;% y2=5;%设置小球的运动轨迹% end% if t2.8% t=t+dt;% a=sin(t-3);% x1=6.1;% y1=5.1;% x3=4-2*sin(1.5*a);% y3=5-2*cos(1.5*a);%设置大球的运动轨迹% end% set(head1,xdata,x1,ydata,y1);%设置球的运动推荐精选% set(head2,xdata,x3,ydata,y3);% drawnow;% end% 2matlab时钟动画% %将下列命令复制到程序运行

4、窗口:%try %可以运行close allhfig=figure(visible,off);set(hfig,NumberTitle,off);set(hfig,name,My Clock);set(hfig,MenuBar,none);set(hfig,color,0.5 0.7 0.3);set(hfig,visible,on);A=linspace(0,6.3,1000);x1=8*cos(A);y1=8*sin(A);x2=7*cos(A);y2=7*sin(A);plot(x1,y1,b,linewidth,1.4)hold onplot(x2,y2,b,linewidth,3.5

5、)fill(0.4*cos(A),0.4*sin(A),r);推荐精选axis offaxis(-10 10 -10 10)axis equalset(gca,position,0.13 0.05 0.775 0.815)title(date,fontsize,18)for k=1:12; xk=9*cos(-2*pi/12*k+pi/2); yk=9*sin(-2*pi/12*k+pi/2); plot(xk/9*8 xk/9*7,yk/9*8 yk/9*7,color,0.3 0.8 0.9) h=text(xk,yk,num2str(k),fontsize,16,color,0.9 0.

6、3 0.8,HorizontalAlignment,center);end% 计算时针位置ti=clock;th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;xh3=4.0*cos(th);yh3=4.0*sin(th);xh2=xh3/2+0.5*cos(th-pi/2);yh2=yh3/2+0.5*sin(th-pi/2);xh4=xh3/2-0.5*cos(th-pi/2);yh4=yh3/2-0.5*sin(th-pi/2);推荐精选hh=fill(0 xh2 xh3 xh4 0,0 yh2 yh3 yh4 0,0.6 0.5 0.3);% 计算

7、分针位置tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;xm3=6.0*cos(tm);ym3=6.0*sin(tm);xm2=xm3/2+0.5*cos(tm-pi/2);ym2=ym3/2+0.5*sin(tm-pi/2);xm4=xm3/2-0.5*cos(tm-pi/2);ym4=ym3/2-0.5*sin(tm-pi/2);hm=fill(0 xm2 xm3 xm4 0,0 ym2 ym3 ym4 0,0.6 0.5 0.3);% 计算秒针位置ts=-(ti(6)/60*2*pi+pi/2;hs=plot(0 7*cos(ts),0 7*sin(ts),color

8、,0.6 0.5 0.3,linewidth,3);set(gcf,doublebuffer,on);k=1;while k6; ti=clock; % 计算时针位置 th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2; xh3=4.0*cos(th); yh3=4.0*sin(th);推荐精选 xh2=xh3/2+0.5*cos(th-pi/2); yh2=yh3/2+0.5*sin(th-pi/2); xh4=xh3/2-0.5*cos(th-pi/2); yh4=yh3/2-0.5*sin(th-pi/2); set(hh,XData,0 xh2 x

9、h3 xh4 0,YData,0 yh2 yh3 yh4 0) % 计算分针位置 tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2; xm3=6.0*cos(tm); ym3=6.0*sin(tm); xm2=xm3/2+0.5*cos(tm-pi/2); ym2=ym3/2+0.5*sin(tm-pi/2); xm4=xm3/2-0.5*cos(tm-pi/2); ym4=ym3/2-0.5*sin(tm-pi/2); set(hm,XData,0 xm2 xm3 xm4 0,YData,0 ym2 ym3 ym4 0) % 计算秒针位置 ts=-(ti(6)/60*2*pi+pi/2; set(hs,XData,0 7*cos(ts),YData,0 7*sin(ts) %drawnow; pause(0.09)end% catch% end推荐精选 (注:可编辑下载,若有不当之处,请指正,谢谢!) 推荐精选

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 医学/心理学 > 基础医学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号