Adjust count values in histogram
이전 댓글 표시
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
On histogram you expect to see the distribution of data itself, so I'm not sure what you exactly mean by second or hr. Say you have a vector of temp for temperature measured at different time points (as you said, in 1 sec intervals):
temp = randsample(1:1:100, 1e4, true, [linspace(eps, 1-eps, 50), flip(linspace(eps, 1-eps, 50))]);
histogram(temp)
xlabel("Temperature")
Sebastian
2022년 3월 1일
"I see from it that the temperature value 40°C was measured in a period of about 500 seconds"
No! it shows the measurement count within the bin. For instance the image below shows there are 482 temperature values within the range (bin) of [39, 42):

If you're interested to change y-axis, see histogram property Normalization: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.histogram-properties.html
Adam Danz
2022년 3월 1일
> Let's use your histogram as an example: I see from it that the temperature value 40°C was measured in a period of about 500 seconds.
As @Ive J mentioned, this is not what the histogram is showing. The y axis of histograms are typically counts, probabilities, frequencies, etc. The y-axis shows the density of values within each x-bin.
Perhaps you could elaborate on your goal and provide an example.
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
2022년 3월 2일
채택된 답변
추가 답변 (1개)
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")
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

