Histogram using Date Stamps
古いコメントを表示
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 件のコメント
Do you mean you want to split all of you data up into 12 months so your histogram has 12 bars or do you want to split all of your data up by month so your histogram has 36 bars (12 months * 3 years)?
Sophia Salazar
2019 年 7 月 26 日
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.
採用された回答
その他の回答 (1 件)
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 件のコメント
Guillaume
2019 年 7 月 26 日
The groupbin could also be 'monthofyear'. The only difference between the two is the format of the name of the bin (char vector for 'monthname', number for 'monthofyear') in the output table.
You probably want to use bar to display the data. If you use histogram, it has to be the
histogram('BinEdges',edges,'BinCounts',counts)
syntax, otherwise you'd be building a histogram of the histogram.
Sophia Salazar
2019 年 7 月 26 日
カテゴリ
ヘルプ センター および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!