필터 지우기
필터 지우기

Making up an array having same date and time

조회 수: 3 (최근 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 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