How to build a time record from several matrices?

2 次查看(过去 30 天)
Hi, I have four matrices A, B, C, D and they are each (1x409752). These matrices are actually extracted from a time record that had format "Y-M-D H:MI:S:MS". A is now equal to H B is equal to MI C is equal to S D is equal to Ms
The start time from "Y-M-D H:MI:S:MS" is 13:58:52.12000 and the end time is 14:01:02.932000. Or from separate matrices: A(1) = 13; B(1) = 58; C(1) = 52; D(1) = 12000;
A(end) = 14; B(end) = 01; C(end) = 02; D(end) = 932000;
How can I combine matrix A, B, C and D to build a time stamp in seconds? I need this time stamp for plotting recorded data.
Many thanks!

回答(2 个)

KSSV
KSSV 2017-4-11
You can read the data from each file and combine them:
t = [A ; B ; C; D] ;

Peter Perkins
Peter Perkins 2017-4-12
If you're using R2014b or newer, use durations:
>> A = [1;2;3;4]; B = [5;6;7;8]; C = [9;10;11;12]; D = [13;14;15;16];
>> dt = duration(A,B,C,D);
>> dt.Format = 'hh:mm:ss.SSS'
dt =
4×1 duration array
01:05:09.013
02:06:10.014
03:07:11.015
04:08:12.016
>> plot(dt,x)
If you are creating A,B,C,D from text, you should skip the middle man and create a datetime from the text, then call timeofday to get the durations.

类别

Help CenterFile 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