您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么使用Matlab繪制有趣的羅盤時(shí)鐘”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“怎么使用Matlab繪制有趣的羅盤時(shí)鐘”文章能幫助大家解決問(wèn)題。
function compassClock % @author : slandarer CCList='零一二三四五六七八九十'; 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; % 計(jì)算獲取年月日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; end monthList=[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)]; % 創(chuàng)建figure窗口及axes坐標(biāo)區(qū)域 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); % 繪制鐘表handle listCell={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); end end set(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) % 循環(huán)繪圖 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; end end
關(guān)于“怎么使用Matlab繪制有趣的羅盤時(shí)鐘”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。