这篇文章主要介绍“怎么使用Matlab绘制有趣的罗盘时钟”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“怎么使用Matlab绘制有趣的罗盘时钟”文章能帮助大家解决问题。绘制效果完整代码function
这篇文章主要介绍“怎么使用Matlab绘制有趣的罗盘时钟”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“怎么使用Matlab绘制有趣的罗盘时钟”文章能帮助大家解决问题。
function compassClock% @author : slandarerCCList='零一二三四五六七八九十';WDList='一二三四五六日';TBList='子丑寅卯辰巳午未申酉戌亥';timeNow=datetime('now');dayNumber=weekday(timeNow);dayNumber=mod(dayNumber-2,7)+1;timeMat=[timeNow.Year,timeNow.Month,timeNow.Day,dayNumber,... ceil((mod(timeNow.Hour+1,24)+1)/2),timeNow.Hour,timeNow.Minute,round(timeNow.Second)];timeMat(6:8)=timeMat(6:8)+1;lastTimeMat=timeMat;% 计算获取年月日char矩阵yearList=[CCList(str2num(num2str(timeMat(1))')'+1),'年'];numList=char(32.*ones(60,3));for i=0:60 tNum=CCList(str2num(num2str(i)')'+1); if length(tNum)>1,tNum=[tNum(1),'十',tNum(2)];end if length(tNum)>1&&abs(tNum(end))==38646,tNum(end)=[];end if length(tNum)>1&&abs(tNum(1))==19968,tNum(1)=[];end numList(i+1,end-length(tNum)+1:end)=tNum;endmonthList=[numList(2:13,:),char(ones(12,1).*26376)];dayList=[numList(2:32,:),char(ones(31,1).*26085)];weekList=[char(ones(7,1).*26143),char(ones(7,1).*26399),WDList'];tbList=[TBList',char(ones(12,1).*26102)];hourList=[numList(1:24,:),char(ones(24,1).*26102)];minuteList=[numList(1:60,:),char(ones(60,1).*20998)];secondList=[numList(1:60,:),char(ones(60,1).*31186)];% 创建figure窗口及axes坐标区域fig=figure('Units','nORMalized','Position',[.2,.05,.55,.82],'Color',[2,34,57]./255);ax=axes('Parent',fig);hold on;set(ax,'Position',[0,0,1,1],'PlotBoxAspectRatio',[1,1,1],'XLim',[-1,1].*1.17,'YLim',[-1,1].*1.17,... 'XColor','none','YColor','none','Color',[2,34,57]./255);% 绘制钟表handlelistCell={yearList,monthList,dayList,weekList,tbList,hourList,minuteList,secondList};numCell={1,12,31,7,12,24,60,60};RCell={0,.22,.39,.53,.64,.78,.96,1.15};for k=1:8 tList=listCell{k}; for i=1:numCell{k} tTheta=2*pi/numCell{k}*(i-1);tNum=mod(i-1+timeMat(k)-1,numCell{k})+1; hdlSet{k,i}=text(ax,cos(tTheta).*RCell{k},sin(tTheta).*RCell{k},tList(tNum,:),'FontName','黑体',... 'Color',[1,1,1],'FontSize',10,'HorizontalAlignment','right','Rotation',tTheta/pi*180); endendset(hdlSet{1,1},'HorizontalAlignment','center')fill(ax,[-.1,1.17,1.17,-.1],[-1,-1,1,1].*.025,[0,0,0],'FaceAlpha',0,'EdgeColor',[1,1,1],'LineWidth',1.2)% 循环绘图while true timeNow=datetime('now'); dayNumber=weekday(timeNow); dayNumber=mod(dayNumber-2,7)+1; timeMat=[timeNow.Year,timeNow.Month,timeNow.Day,dayNumber,... ceil((mod(timeNow.Hour+1,24)+1)/2),timeNow.Hour,timeNow.Minute,round(timeNow.Second)]; timeMat(6:8)=timeMat(6:8)+1; K=find(lastTimeMat~=timeMat); if ~isempty(K) for k=K tList=listCell{k}; for i=1:numCell{k} tNum=mod(i-1+timeMat(k)-1,numCell{k})+1; set(hdlSet{k,i},'String',tList(tNum,:)) end end end lastTimeMat=timeMat; drawnow;endend
关于“怎么使用Matlab绘制有趣的罗盘时钟”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注编程网精选频道,小编每天都会为大家更新不同的知识点。
--结束END--
本文标题: 怎么使用Matlab绘制有趣的罗盘时钟
本文链接: https://lsjlt.com/news/348845.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0