MATLAB Answers

Difference between datetime values in minutes

조회 수: 6(최근 30일)
Tycho Maas
Tycho Maas 2020년 12월 30일
댓글: Ameer Hamza 2020년 12월 30일
I need some help. I have an array with multiple columns and with in one of these columns dates+times as a datetime format, this array is linked as data_combined.mat. The array looks like this:
06-Dec-2020 00:04:00 '06-Dec-2020' 7 76.8566666666667
06-Dec-2020 00:20:00 '06-Dec-2020' 6.30000000000000 77.6833333333333
06-Dec-2020 00:40:00 '06-Dec-2020' 5.10000000000000 78.7166666666667
I need help calculating the difference between the datetimes in minutes and creating a column containing these values. For example, this is what the above array would then look like:
1 06-Dec-2020 00:04:00 '06-Dec-2020' 7 76.8566666666667
17 06-Dec-2020 00:20:00 '06-Dec-2020' 6.30000000000000 77.6833333333333
37 06-Dec-2020 00:40:00 '06-Dec-2020' 5.10000000000000 78.7166666666667
Can anybody help me writing some code to do this?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 30일
Try this
col = minutes([all_combined_short{:,1}].'-all_combined_short{1,1})+1;
all_combined_short = [num2cell(col), all_combined_short]
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2020년 12월 30일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by