Converting timestamp from TDMS LabView

13 Ansichten (letzte 30 Tage)
Hany Ferdinando
Hany Ferdinando am 29 Jan. 2025
Kommentiert: Star Strider am 30 Jan. 2025
I received measurement data using LabView as a TDMS file and use TDMS reader from https://se.mathworks.com/matlabcentral/fileexchange/30023-tdms-reader to import it. The file name itself already indicated date and time of the measurement, e.g., COP_meas1_25-01-27_1237.tdms, but the resolution was only 1 s.
Using excel with AddOn from NI, I got the following results:
From values attached to this question.
Using
datetime(timestamp(1:5),'ConvertFrom','datenum','TicksPerSecond',1e4,'Format','HH:mm:ss.SSSS')
I got the following results.
05:37:04.1507
05:37:04.1520
05:37:04.1532
05:37:04.1545
05:37:04.1557
Using
datetime(timestamp(1),'ConvertFrom','posixtime')
I got
09-Jan-1970 13:27:24
I have tried using various combinations but I failed. How should I use the parameters to get the same results as in Excel?

Akzeptierte Antwort

Star Strider
Star Strider am 29 Jan. 2025
Bearbeitet: Star Strider am 29 Jan. 2025
I did not see the .mat file before, although I did look for it.
Try this —
LD = load('timestamp.mat')
LD = struct with fields:
timestamp: [1124000x1 double]
format long
timestamp = LD.timestamp
timestamp = 1124000×1
1.0e+05 * 7.396442340758194 7.396442340758338 7.396442340758482 7.396442340758628 7.396442340758773 7.396442340758917 7.396442340759061 7.396442340759206 7.396442340759351 7.396442340759496
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Time24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='+02:00')
Time24 = 1124000x1 datetime array
01/27/2025 05:37:04.150 01/27/2025 05:37:04.152 01/27/2025 05:37:04.153 01/27/2025 05:37:04.154 01/27/2025 05:37:04.155 01/27/2025 05:37:04.157 01/27/2025 05:37:04.158 01/27/2025 05:37:04.159 01/27/2025 05:37:04.160 01/27/2025 05:37:04.162 01/27/2025 05:37:04.163 01/27/2025 05:37:04.164 01/27/2025 05:37:04.165 01/27/2025 05:37:04.167 01/27/2025 05:37:04.168 01/27/2025 05:37:04.169 01/27/2025 05:37:04.170 01/27/2025 05:37:04.172 01/27/2025 05:37:04.173 01/27/2025 05:37:04.174 01/27/2025 05:37:04.175 01/27/2025 05:37:04.177 01/27/2025 05:37:04.178 01/27/2025 05:37:04.179 01/27/2025 05:37:04.180 01/27/2025 05:37:04.182 01/27/2025 05:37:04.183 01/27/2025 05:37:04.184 01/27/2025 05:37:04.185 01/27/2025 05:37:04.187
LastLine24 = Time24(end)
LastLine24 = datetime
01/27/2025 06:00:29.149
TimeAP = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy hh:mm:ss.SSS a', TimeZone='+02:00')
TimeAP = 1124000x1 datetime array
01/27/2025 05:37:04.150 AM 01/27/2025 05:37:04.152 AM 01/27/2025 05:37:04.153 AM 01/27/2025 05:37:04.154 AM 01/27/2025 05:37:04.155 AM 01/27/2025 05:37:04.157 AM 01/27/2025 05:37:04.158 AM 01/27/2025 05:37:04.159 AM 01/27/2025 05:37:04.160 AM 01/27/2025 05:37:04.162 AM 01/27/2025 05:37:04.163 AM 01/27/2025 05:37:04.164 AM 01/27/2025 05:37:04.165 AM 01/27/2025 05:37:04.167 AM 01/27/2025 05:37:04.168 AM 01/27/2025 05:37:04.169 AM 01/27/2025 05:37:04.170 AM 01/27/2025 05:37:04.172 AM 01/27/2025 05:37:04.173 AM 01/27/2025 05:37:04.174 AM 01/27/2025 05:37:04.175 AM 01/27/2025 05:37:04.177 AM 01/27/2025 05:37:04.178 AM 01/27/2025 05:37:04.179 AM 01/27/2025 05:37:04.180 AM 01/27/2025 05:37:04.182 AM 01/27/2025 05:37:04.183 AM 01/27/2025 05:37:04.184 AM 01/27/2025 05:37:04.185 AM 01/27/2025 05:37:04.187 AM
LastLineAP = TimeAP(end)
LastLineAP = datetime
01/27/2025 06:00:29.149 AM
I prefer 24-hour time. I posted conversions for both here.
I am not certain what sort of resolution you want (or what the data provide). I have them in µs here. Append more ‘S’ characters to get additional displayed precision.
The Format name-value pair determines how the datetime values are displayed. It keeps full internal precision regardless.
EDIT — (29 Jan 2025 at 13:22)
Adeded timestamp.mat file import and changed the datetime calls to accommodate it.
EDIT — (29 Jan 2025 at 14:42)
Corrected (added) time zone offset, changed seconds resolution from 6 to 3 (µs to ms). .
.
  7 Kommentare
Hany Ferdinando
Hany Ferdinando am 30 Jan. 2025
Thanks, Star! I realy appreciate your effort to help me! I just knew that we can twist the time zone after creating datetime!
Star Strider
Star Strider am 30 Jan. 2025
As always, my pleasure!
The solution was defining the TimeZone of the original as 'Z' (or equivalently, 'UTC'), although I thought that was the default. After that, defining the other time zones is straightforward.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by