1970 matla 时间_在MATLAB中绘制时间序列数据
我經(jīng)常與 posix 時(shí)間(即 unixtime )與其他程序一起工作,但在matlab中,處理時(shí)間和日期的最簡單格式是Matlab時(shí)間序列號格式 .
要從 Unix 轉(zhuǎn)換為 Matlab ,我廣泛使用一個(gè)小的轉(zhuǎn)換函數(shù):
function matlabtime = unix2matlabtime(unixtime)
%// function matlabtime = unix2matlabtime(unixtime)
%//
%// input : ** unixtime ** : time vector in the UNIX time serial number
%// representation (seconds since 01-jan-1970)
%//
%// output : ** matlabtime ** : time vector in the Matlab time serial number
%// representation (days since 01-jan-0000)
pivot = datenum([1970 01 01 00 00 00]) ;
matlabtime = ( unixtime / 24 / 3600 ) + pivot ;
將此功能保存在路徑上的某個(gè)位置,您可以如下繪制數(shù)據(jù):
%// Generate sample data
sampleunixtime = linspace( 1427205640 , 1427205900 ).' ; %'// ignore this comment
DATA = [sampleunixtime , sin(sampleunixtime./10) ] ;
%// get a time vector in Matlab time serial format, then plot
time = unix2matlabtime( DATA(:,1) ) ;
plot( time, DATA(:,2) )
%// Adjust X-Ticks in human readable format
set( gca , 'XTickLabel' , datestr( get(gca,'XTick'),'HH:MM:SS' ) )
獲得:
查看datenum和datestr文檔,了解如何處理這些問題 . 日期/時(shí)間有許多預(yù)定義的輸出格式,或者您甚至可以構(gòu)建自己的輸出格式以提高所需的精度(添加毫秒,刪除秒,添加日期等...) .
請注意 XTickLabel 現(xiàn)在已被覆蓋,因此它們不會(huì)自動(dòng)更新 . 因此,如果你的數(shù)字是 zoom 或 pan ,你將不得不重新運(yùn)行最后一行代碼來刷新 XTicks 值 .
(就個(gè)人而言,我將最后一行代碼放在Matlab工具欄快捷方式中,以便隨時(shí)快速訪問它) .
總結(jié)
以上是生活随笔為你收集整理的1970 matla 时间_在MATLAB中绘制时间序列数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DS8100更换PPS电源线
- 下一篇: 高阻态是0还是1_超实用买鞋指南!宽脚、