Organizing and calculating with timestamps and numbers.

6 views (last 30 days)
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.

Accepted Answer

John Doe
John Doe on 8 Oct 2019
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 Comments
Neko Benítez
Neko Benítez on 9 Oct 2019
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!