MATLAB 绘制时钟(同步当前时间)

Posted slandarer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB 绘制时钟(同步当前时间)相关的知识,希望对你有一定的参考价值。

写了 一个很简单的MATLAB时钟,依靠clock()函数获取当前时间并转化为角度并进行指针更替,
运行效果:



完整代码:

function myClock
% @author:slandarer

fig=figure();
screenSize=get(0,'ScreenSize');
fig.Position=[screenSize(1,[3,4])./10,...
    screenSize(4).*0.6,screenSize(4).*0.6];
fig.Name='clockBySlandarer';
fig.NumberTitle='off';
ax=axes(fig);
ax.Position=[0 0 1 1];
hold(ax,'on');
ax.XLim=[-1 1];
ax.YLim=[-1 1];
ax.XTick=[];
ax.YTick=[];
ax.XColor='none';
ax.YColor='none';
ax.Color=[249,247,246]./255;
%ax.DataAspectRatio=[1 1 1];

tSub=linspace(pi/2,-3*pi/2,61);
tBas=linspace(pi/2,-3*pi/2,13);
plot([cos(tSub).*0.98;cos(tSub).*0.93],[sin(tSub).*0.98;sin(tSub).*0.93],'k','LineWidth',2.8)
plot([cos(tBas).*0.98;cos(tBas).*0.87],[sin(tBas).*0.98;sin(tBas).*0.87],'k','LineWidth',6)


for i=1:12
    text(cos(tBas(i+1)).*0.78,sin(tBas(i+1)).*0.78,...
        num2str(i),'Color',[46,46,45]./255,...
        'FontSize',18,'HorizontalAlignment','center',...
        'FontName','Cambria','FontWeight','bold')  
end


text(0,-0.28,' BY SLANDARER','FontName','Cambria','Color',[46,46,45]./255,...
     'FontSize',15,'HorizontalAlignment','center')
text(0,-0.38,' CSDN','FontName','Cambria','Color',[96,96,95]./255,...
     'FontSize',14,'HorizontalAlignment','center')
 
hou_Hdl=plot([0,0],[0,0.6],'k','LineWidth',8);
min_Hdl=plot([0,0],[0,0.8],'k','LineWidth',4.5,'Color',[46,46,45]./255);
sec_Hdl=plot([0,0],[-0.1,0.91],'k','LineWidth',3,'Color',[243,168,41]./255);

scatter(0,0,150,'filled','CData',[243,168,41]./255)

while true
    tempTime=clock();
    hou_t=mod(tempTime(4)+tempTime(5)/60+tempTime(6)/3600,12)/12;
    hou_t=pi/2-2*pi*hou_t;
    min_t=(tempTime(5)+tempTime(6)/60)/60;
    min_t=pi/2-2*pi*min_t;
    sec_t=tempTime(6)/60;
    sec_t=pi/2-2*pi*sec_t;
    
    hou_Hdl.XData=[0,cos(hou_t).*0.6];
    hou_Hdl.YData=[0,sin(hou_t).*0.6];
    min_Hdl.XData=[0,cos(min_t).*0.8];
    min_Hdl.YData=[0,sin(min_t).*0.8];
    sec_Hdl.XData=[-cos(sec_t).*0.1,cos(sec_t).*0.91];
    sec_Hdl.YData=[-sin(sec_t).*0.1,sin(sec_t).*0.91];
    drawnow
end

end

以上是关于MATLAB 绘制时钟(同步当前时间)的主要内容,如果未能解决你的问题,请参考以下文章

MATLAB绘制罗盘时钟

目标定位基于matlab UWB卡尔曼滤波追踪无线时钟同步误差含Matlab源码 1626期

OpenCV-Python实战(番外篇)——OpenCV中绘制模拟时钟显示当前时间

9.3.3 QPainter绘制模拟时钟实例

[工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls(代码片段

canvas基础绘制-绚丽时钟