Insert Date Column Based off Known Start and Stop Time
Show older comments
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 Comment
the cyclist
on 7 Feb 2017
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.
Answers (2)
Peter Perkins
on 8 Feb 2017
0 votes
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.
Daniel Devereaux
on 8 Feb 2017
0 votes
1 Comment
Peter Perkins
on 9 Feb 2017
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)
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.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!