hObject=figure; set(hObject,'NumberTitle','off'); set(hObject,'MenuBar','none'); set(hObject,'visible','on'); A=linspace(0,2*pi,1000); % 0到6.3之间产生1000个点,此为极坐标:0~2pi x1=8*cos(A); y1=8*sin(A); %设置外圆所对应的x,y值 x2=7*cos(A); y2=7*sin(A); %设置内圆所对应的x,y值 plot(x1,y1,'b','linewidth',1) hold on plot(x2,y2,'b','linewidth',3.5,'color',[0 0 0]) fill(0.4*cos(A),0.4*sin(A),'r');%时钟中心小实心圆点 axis off; %取消坐标轴显示 axis equal;%坐标轴x,y等比率 for k=1:12; %时钟面盘12等分,并写上相应的1,2...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',[1 0 0]) h=text(xk,yk,num2str(k),'fontsize',16,'color',... [1 0 0],'HorizontalAlignment','center'); end for k=1:60 xk=7.5*cos(-2*pi/60*k+pi/2); yk=7.5*sin(-2*pi/60*k+pi/2); plot([xk/8*8 xk/8*7],[yk/8*8 yk/8*7],'color',[1 0 0]) s=num2str(mod(k,5)); if (mod(k,5))==0 s=''; end h=text(xk,yk,s,'fontsize',10,'color',... [0 0 0],'HorizontalAlignment','center'); end % 计算时针位置 ti=clock; % 得到当前的时间 th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2; % 4、5、6分别为时、分、秒 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],[1 0 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); hm=fill([0 xm2 xm3 xm4 0],[0 ym2 ym3 ym4 0],[0 1 0]); % 计算秒针位置 ts=-(ti(6))/60*2*pi+pi/2; hs=plot([0 7*cos(ts)],[0 7*sin(ts)],'color',[0 0 1],'linewidth',3);
标签:xk,cos,0.5,yk,Matlab,钟表,pi,制作,sin From: https://www.cnblogs.com/bbhhh/p/17825894.html