Histogram using Date Stamps

조회 수: 37 (최근 30일)
Sophia Salazar
Sophia Salazar 2019년 7월 26일
댓글: Sophia Salazar 2019년 7월 26일
I have three years of dates and I want to know how to make a histogram only taking months into consideration.
The data is in datestam format, so when I plot a histogram is separates the months for each year.
How do I do this?
Thanks!
  댓글 수: 3
Sophia Salazar
Sophia Salazar 2019년 7월 26일
Sorry about the unclear question! My data is in date stamps (like this: 2012-01-21) , in datetime format.
I have three years, so when I plot a histogram as is, it produces 36 bars, one for each month in each year.
What I want is 12 bars, so for example, the January bar should include all January values for all three years.
Does this clear up my question?
Thanks for the quick response!
Adam Danz
Adam Danz 2019년 7월 26일
That's clearer! If you get stuck with the recommendation in my answer, leave a comment and I can try to help further.

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

채택된 답변

Guillaume
Guillaume 2019년 7월 26일
Oh, if it's the histogram of the dates you want, then groupsummary may not be the best tool (sorry Adam!)
histogram(yourdatetimevector.Month, 'BinMethod', 'integers')
  댓글 수: 2
Adam Danz
Adam Danz 2019년 7월 26일
Just saw this after my ans update, no prob at all!
Sophia Salazar
Sophia Salazar 2019년 7월 26일
This worked beautifully! Thanks to both of you guys!

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

추가 답변 (1개)

Adam Danz
Adam Danz 2019년 7월 26일
편집: Adam Danz 2019년 7월 26일
If your data are organized in a table or array, use groupsummary() (requires r2018a). The groupbin should be 'monthname'(see Guillaume's comment below). Then feed that summary data into historgram().
[update]
If you're just counting the number of months in a datetime vector, you can use month() along with histcounts().
% dt is your datetime vector
c = histcounts(month(dt),1:13);
mo = {'jan' 'feb' 'mar' 'apr' 'may' 'jun' 'jul' 'aug' 'sep' 'oct' 'nov' 'dec'};
histogram('categories',mo,'BinCounts',c)
  댓글 수: 3
Sophia Salazar
Sophia Salazar 2019년 7월 26일
I'm not sure I completley understand how this works, or if it is compatible with datetime types. I don't understand how to apply groupsummary to my data based on looking at the examples on its page.
I'm using a 900000x1 datetime array.
Adam Danz
Adam Danz 2019년 7월 26일
@Sophia, see updated answer.

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by