Effacer les filtres
Effacer les filtres

Making up an array having same date and time

3 vues (au cours des 30 derniers jours)
Yongmin
Yongmin le 6 Jan 2015
Commenté : Yongmin le 6 Jan 2015
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!

Réponse acceptée

Guillaume
Guillaume le 6 Jan 2015
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 commentaire
Yongmin
Yongmin le 6 Jan 2015
Thank you so much for your kind answer!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by