Organizing and calculating with timestamps and numbers.

조회 수: 7 (최근 30일)
Neko Benítez
Neko Benítez 2019년 10월 8일
편집: Stephen23 2019년 10월 9일
I have a matrix, in which in the first column I have timestamps, usually one every 10 seconds, but it is not constant, and sometimes there are more than 10 seconds between one timestamp and another. The second column is power readings (numbers). A brief example would be something like this:
1570226408 1000022
1570226418 1000022
1570226431 1000022
1570226438 1000032
1570226448 1000032
1570226458 1000032
1570226469 1000032
I converted the timestamps into DateTime format, but the problem is that I can not have in the same matrix, two different classes (DateTime and double).
What I want to do is to be able to process that file, to calculate the total power per hour, per day, the energy for each hour or the total energy per day. Do you have any idea about how to do this?
PS. I managed to do this in a very rustic way: convert the timestamp into date number and work with the decimals of those date numbers to differentiate hours, but I reckon there should be a more efficient and straightforward way to do this.

채택된 답변

John Doe
John Doe 2019년 10월 8일
Create a table - a table can handle both datetime, double, single etc.
t = array2table(data)
You can then do your analysis as you please using datetime. To call a variable use:
t.VariableName
Timetable can also be used.
doc timetable
  댓글 수: 2
Neko Benítez
Neko Benítez 2019년 10월 9일
Thank you very much, John. I checked, and it worked. I have to check the advantages of using timetable instead of just a table. As I said, I need to group data for each hour, day, and so on. Once I have all the time data in column 1 of the table, do you suggest any precise way to group the matching data for hours, days and so on?

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

추가 답변 (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