Hi,
I have some data from a sensor and corresponding timestamps. How do I plot this data? (x axis - timestamps, y-axis - data) plot function gives empty figures. Probably because timestamps cannot be put in a linear scale. I tried semilogx - this also gives empty figures.
How do I do this?
Thanks in advance

댓글 수: 2

Ryan Smith
Ryan Smith 2016년 11월 28일
Can you provide the data as an attachment?
lexi11
lexi11 2016년 11월 28일
Hi, the timestamps are in unix format. I have attached a set of them. Since in excel it shows as 1.48E+10 format, I have changed the type in excel to 'number' so that you can see the entire number. So it adds .00 in the end to each value, but originally I get in the 1.48E+10 like number representation. Thank you.

댓글을 달려면 로그인하십시오.

 채택된 답변

dpb
dpb 2016년 11월 28일
편집: dpb 2016년 11월 28일

1 개 추천

Convert from whatever format the timestamps are in to a Matlab representation of dates...with R2014 up, there's the datetime class; prior to that use datenum. See <datetime> for current versions; plot is datetime -aware.

댓글 수: 7

Walter Roberson
Walter Roberson 2016년 11월 28일
datetime() offers a 'ConvertFrom', 'posixtime'. The numbers you showed in the image convert into dates today if you divide them by 1000 before doing the conversion.
lexi11
lexi11 2016년 11월 28일
This works!!! Thank you very much, dpb and Walter.
lexi11
lexi11 2016년 11월 30일
Hi Walter, I would also like to know why we divide by 1000? Is this a standard procedure? Thanks.
Munshi Mahbubur Rahman
Munshi Mahbubur Rahman 2018년 10월 30일
what have you guys used for the dateType argument? My data is in unix timestamp
dpb
dpb 2018년 10월 30일
Well, Unix timestamp is in seconds from Jan 1, 1970 but your data are too big for that; they seem to have been encoded as integer values to the millisecond resolution...
>> t=datetime(1489337264031/1000,'ConvertFrom','posixtime')
t =
datetime
12-Mar-2017 16:47:44
>> t.Format=[t.Format '.SSS']
t =
datetime
12-Mar-2017 16:47:44.031
>>
You'll notice the fractional seconds match up with the last significant digits in the original number.
In recent versions of MATLAB, you can also convert directly from ms since 1970:
>> datetime(1489337264031,'ConvertFrom','EpochTime','TicksPerSecond',1000,'Format','dd-MMM-yyyy HH:mm:ss.SSS')
ans =
datetime
12-Mar-2017 16:47:44.031
The 'Epoch' parameter defaults to 1-Jan-1970, which is convenient if you have posix timestamps.
dpb
dpb 2018년 10월 31일
Thanks for making aware of that, Peter...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2016년 11월 28일

댓글:

dpb
2018년 10월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by