Plot data with time in miliseconds

Hi all, I have the following problem: I read from a text file the time and the corresponding value of an output signal. The time stamp has the following format: 2017-06-12 13:46:31.486. The file has thousands of measurement samples. How can I plot a certain part of the signal and see on the x-axis the time stamps in miliseconds resolution?

 採用された回答

dpb
dpb 2017 年 6 月 26 日
編集済み: dpb 2017 年 6 月 28 日

1 投票

>> fmt='yyyy-MM-dd HH:mm:ss.SSS''
>> dtn=datetime('2017-06-12 13:46:31.486','Inputformat',fmt)
dtn =
12-Jun-2017 13:46:31
>> dtn.Format=fmt
dtn =
2017-06-12 13:46:31.486
Plot against dtn and zoom in to heart's content to see detail. >>

5 件のコメント

Nik__
Nik__ 2017 年 6 月 28 日
編集済み: Nik__ 2017 年 6 月 28 日
At first it didn't work properly, but then I saw a mismatch in the format -> mm was switched with ss. After replacing them it works perfect!
>> dtn=datetime('2017-06-12 13:46:31.486','Inputformat','yyyy-MM-dd HH:mm:ss.SSS') >> dtn.Format='yyyy-MM-dd HH:mm:ss.SSS'
dpb
dpb 2017 年 6 月 28 日
Huh....I see I did transpose that somehow...good catch.
Think maybe I had the MM and mm interchanged initially; the inconsistency in the definition makes it and extremely difficult function to use; one has to always look up "who's who in the zoo". Why they couldn't have at least made all the mo/da/yr upper/lower case instead of mixing is beyond my comprehension...so now you remember they're mixed but how in the world to recall which is which??? :( /End codger rant/
Steven Lord
Steven Lord 2017 年 6 月 28 日
The format used by the older date handling functions like datestr predates the start of my time at MathWorks, but I believe it was something we developed on our own.
For datetime we switched to using a subset of the Unicode® Locale Data Markup Language (LDML) as stated in this guest post on Loren's blog in 2015. [See the end of the " datetime for Points in Time " section.] The symbol table in Section 8 of Unicode Technical Standard #35 should look at least somewhat familiar if you've read through the documentation on the datetime Format property.
I don't remember offhand when this was introduced, but we do try to help you catch when you use MM instead of mm or vice versa. In release R2017a:
>> datetime('06/28/2017', 'InputFormat', 'mm/dd/yyyy')
Warning: The format 'mm/dd/yyyy' contains a field for minute (m) in
what appears to be a date portion. You might have intended to use
the symbol for month (M) rather than for minute (m). See the
datetime.Format property for a complete description of the identifiers
used in format character vectors.
[I reformatted the warning message to fit the width of the Answers display, so you don't have to scroll to read the whole message.]
dpb
dpb 2017 年 6 月 28 日
編集済み: dpb 2017 年 6 月 28 日
My bad, Steven, apologies. :)
The "they" above in context implies TMW granted, but not who I was thinking of; I was already aware the reference from whence the abbreviations come is of external origin so was meaning in that document. No way could have known that, so mea culpa, a thousand wet-noodle lashings! :)
I still don't see why THAT "THEY" couldn't have had more consistency, what's so special about 'MM' it simply had to be capitalized in the date portion while years and days are lowercase and vice versa with hours,minutes,seconds? Makes no sense to me at all. And, similarly, why not reserve the opposite case of the rest for the fractional part of the seconds? "Normalize, normalize!"
The error missives will help, it would be better if it could show up in the auto-type feature somehow, though, to prevent the mistake before instead of after. Probably too much parsing to be practical, but "just sayin'" :)
Wherever the fundamental blame lies for the particular encoding (and clearly this isn't TMW, yes :) ) it makes for a very user-belligerent interface owing to trying to keep it all straight. I suppose if this was one of the most frequent usages one made eventually it would become ingrained but for the occasional/newer user it's just a nuisance and highly error-prone.
dpb
dpb 2017 年 6 月 28 日
PS. Worth pointing out for the record again where it did come from though, and that it really isn't you'se guys' fault this time! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

製品

質問済み:

2017 年 6 月 26 日

編集済み:

dpb
2017 年 6 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by