Making up an array having same date and time
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have an array of time and want to compute elapsed time from the first element of the array. For example, I have an array of event arrival times as follows:
arrival_time =
2015 1 1 0 0 0
2015 1 1 0 0 6
2015 1 1 0 0 8
2015 1 1 0 0 8
2015 1 1 0 0 9
2015 1 1 0 0 11
2015 1 1 0 0 11
2015 1 1 0 0 12
2015 1 1 0 0 15
2015 1 1 0 0 15
2015 1 1 0 0 16
2015 1 1 0 0 18
2015 1 1 0 0 18
2015 1 1 0 0 18
2015 1 1 0 0 20
2015 1 1 0 0 23
2015 1 1 0 0 23
2015 1 1 0 0 24
2015 1 1 0 0 25
2015 1 1 0 0 26
2015 1 1 0 0 27
2015 1 1 0 0 27
2015 1 1 0 0 29
And I would like to compute elapsed time from arrival_time(1,:).
Question 1. How do I compute the elapsed time easily?
Question 2 . I am going to use the function etime(t2,t1)
t2 = arrival_time(2:end,:);
Then how do I make t1 array that has same element arrival_time(1,:) ?
Many thanks!
0 个评论
采纳的回答
Guillaume
2015-1-6
arrival_time = datetime(arrival_time);
ellapsed_time = arrival_time - arrival_time(1);
%to get it in seconds:
ellapsed_seconds = seconds(ellapsed_time);
If you don't have datetime you can do this:
start_time = repmat(arrival_time(1, :), size(arrival_time, 1), 1);
ellapsed_seconds = etime(arrival_time, start_time);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!