date time convert to elapsed time

I have a vector of date times in 'HH:MM:SS' format which I want to convert to elapsed time. Each cell is a 1 minute increment from the previous.
Right now I'm doing a for loop that loops the size of the entire vector, and does x(i)-x(1) to calculate the elapsed time (in minutes).
This seems kind of cumbersome code, and I feel like there's an easier way. Any recommendations?

 採用された回答

Thomas
Thomas 2012 年 4 月 25 日

1 投票

your cell array
c={'12:00:00' '12:00:01' '12:00:02' '12:00:03'}
d=datenum(c,'HH:MM:SS')
out=d-d(1);
time_sec=out*86400

1 件のコメント

David C
David C 2012 年 4 月 25 日
super! Thanks guys!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 4 月 25 日

0 投票

datenum() the cell array of date strings to get out a vector of serial date numbers. Subtract the first value from the array to get the elapsed times in days. Multiply by 24*60 to get elapsed times in minutes. No loop should be needed.

1 件のコメント

Jamiat Nanteza
Jamiat Nanteza 2023 年 11 月 2 日
Thank you. You saved me

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

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

質問済み:

2012 年 4 月 25 日

コメント済み:

2023 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by