Adjust count values in histogram

10 ビュー (過去 30 日間)
Sebastian
Sebastian 2022 年 3 月 1 日
コメント済み: Adam Danz 2022 年 3 月 2 日
Hello
I have a vector of temperature values taken in 1 second increments. I want to use the "histogram" command to show in which time period which temperatures were measured. This will work correctly for the time unit seconds. But I want to display these seconds (y-values) now in hours. I don't know how to change the "Values" attribute to do this.
Thanks for the help.
  8 件のコメント
jessupj
jessupj 2022 年 3 月 1 日
I think you'd want to do something like this
ggg = gca;
ggg.YTickLabels = cellfun(@str2num, ggg.YTickLabels )/3600
that converts the current yticklabel strings to numbers and scales them by some factor. of course, this will be ugly without specificying precision.
Adam Danz
Adam Danz 2022 年 3 月 2 日
That's clearer @Sebastian. If my answer doesn't address your question please let us know.

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

採用された回答

Adam Danz
Adam Danz 2022 年 3 月 2 日
If temperature data is collected a 1-second interval, then a histogram of temperature data will show the number of temperature samples within each bin which can also be interpreted as the amount of time in seconds that data was collected within each bin.
To convert time to hours, use histcounts to retreive the bin heights, divide by 60 twice to convert from seconds to hours, and then plot the results using histogram.
% Create demo data
x = randn(1,30000)*10 + 35;
% Compute bin counts at 10-deg bin widths (you can change this)
[counts, bins] = histcounts(x,'BinWidth', 10);
% Convert counts (one sample per second) to hours
countHrs = counts/60/60;
% plot results
histogram('BinEdges',bins,'BinCounts',countHrs)
ylabel('Sum of sample intervals (hrs)')
xlabel('Temperature (c)')

その他の回答 (1 件)

David Hill
David Hill 2022 年 3 月 1 日
Use normalization (probability) to get what you want.
temp = randsample(1:1:100, 1e4, true, [linspace(eps, 1-eps, 50), flip(linspace(eps, 1-eps, 50))]);
histogram(temp,'Normalization','probability')
xlabel("Temperature")

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by