Making up an array having same date and time

1 回表示 (過去 30 日間)
Yongmin
Yongmin 2015 年 1 月 6 日
コメント済み: Yongmin 2015 年 1 月 6 日
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!

採用された回答

Guillaume
Guillaume 2015 年 1 月 6 日
If you're on 2014b, use datetime objects:
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);
  1 件のコメント
Yongmin
Yongmin 2015 年 1 月 6 日
Thank you so much for your kind answer!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by