How can I count how many rows in a table have the same date?

4 ビュー (過去 30 日間)
Andreas B
Andreas B 2018 年 6 月 12 日
コメント済み: Peter Perkins 2018 年 7 月 5 日
Hey Guys,
I would like to count how many rows are within one day. Please take a look on the Image. There are a lot of rows an they differ from day to day. I simple want to count them and safe this number in a variable.
The next question I have is, how can I count rows within a day and a time period. Like I want to know how man Logs a created from 00:00 to 02:00 am, then from 02:00 - 04:00 pm.
Thank you for your help.
Best regards Andreas
  1 件のコメント
jonas
jonas 2018 年 6 月 12 日
編集済み: jonas 2018 年 6 月 12 日
You probably want to use either the unique() function or logical indexing, can you upload some data to work with?

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

回答 (3 件)

Sean de Wolski
Sean de Wolski 2018 年 6 月 14 日
編集済み: Sean de Wolski 2018 年 6 月 14 日
convert table to timetable table2timetable.
retime the timetable with count as the function

Sam Cook
Sam Cook 2018 年 6 月 14 日
First, you need a range of times (buckets/intervals) to check. This will vary depending on exactly what time periods you're interested in (hourly, daily, etc). Here the time period is every 2 hours from June 13 to June 14.
times = datetime(2018, 6, 13):hours(2):datetime(2018, 6, 14);
Then, for each interval, you want to count the number of rows that are within that interval. Again, this code will vary based on how your data is formatted. In this example, 'data' is a datetime vector.
counts = zeros(1, length(times) - 1);
for i=1:length(times) - 1
intStart = times(i);
intEnd = time(i + 1);
counts(i) = nnz(data > intStart & data <= intEnd);
end
These counts refer to their respective interval (EG counts(1) is the number of entries from times(1) to times(2), counts(5) from times(5) to times(6), etc).
  1 件のコメント
Peter Perkins
Peter Perkins 2018 年 7 月 5 日
histcounts is more or less a one-liner for that loop.

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


Walter Roberson
Walter Roberson 2018 年 6 月 14 日

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by