Insert Date Column Based off Known Start and Stop Time

Hello,
I have processed data that covers a 5 month period and have 3 columns of data that give me the x, y, and z rotation of an object. The data is divided by data points and not by time. I know the start and stop time for the data logging. What is the best way to create a date field that I can fill in the start and end time? Ideally I'd like to plot these values with known date values instead of just the data point value on the x-axis.

1 个评论

It would be a lot easier to understand your question if you posted a small (but representative) example of the input/output you expect.
Don't just describe it. Post actual code, or upload a MAT file.

请先登录,再进行评论。

回答(2 个)

It sounds like maybe you want a table that contains two datetime variables as well as x, y, and z, but as the cyclist says, you're gonna have to provide more details.
Hi. I've attached a MAT file that covers 3 hours of data. The unit collects data points at 100hz for 10min every 3 hrs. So it runs for 10 mins after the following start time with each data point representing .01 of a second.
Start time: 6:08:00 PM UTC 2016-05-22
How would I be able to plot these three columns of data (x,y,z) against time referenced to this start time in that increment?

1 个评论

Here's some code that works in R2016b:
>> t0 = datetime('6:08:00 PM UTC 2016-05-22','InputFormat','hh:mm:ss a ''UTC'' yyyy-MM-dd');
>> t0.Format = 'yyyy-MM-dd HH:mm:ss.SSS';
>> d = (minutes(0):milliseconds(10):minutes(10))';
>> t = t0 + d;
>> xyz = cumsum(randn(length(t),3));
>> tt = array2timetable(xyz,'RowTimes',t,'VariableNames',{'x' 'y' 'z'})
tt =
Time x y z
_______________________ ______ ________ ________
2016-05-22 18:08:00.000 0.2992 -0.95717 0.01993
2016-05-22 18:08:00.010 1.7475 -1.054 -0.52164
2016-05-22 18:08:00.020 2.2103 -0.2601 -0.66848
2016-05-22 18:08:00.030 2.7189 0.69421 -0.41496
2016-05-22 18:08:00.040 2.381 0.28662 -1.789
2016-05-22 18:08:00.050 4.5419 0.76694 -0.78308
2016-05-22 18:08:00.060 3.748 1.9123 -2.2305
2016-05-22 18:08:00.070 2.7249 0.9289 -3.7441
2016-05-22 18:08:00.080 2.4665 2.068 -3.9346
2016-05-22 18:08:00.090 1.3154 1.2933 -4.4244
[snip]
Plot all three vars on one axis:
plot(tt.Time,tt.Variables)
legend(tt.Properties.VariableNames)
Plot on separate axes (using ttplot from the File Exchange):
ttplot(tt)
Both can also be done prior to R2016b, using a table, not a timetable.
Hard to know how you want to handle those 2hr 50min gaps, the above only plots one segment.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by