Histogram fraction of total observations and fraction per unit width

19 views (last 30 days)
I'm working on a HW problem and I am kind of stuck. I took a class in Matlab several semesters ago and am now in a class where our HW is exclusivly done in Matlab. I've been given a data set where I have to use that data to create a series of histograms. The first histogram is the number of observations over the measuered data, no problem. The second and third histograms ask that I take the given data and display the fraction of total observations over each interval, and display the fraction per unit width over each interval. Is there an easy way to go about doing this or am i going to have to resort to doing the math and creating my graphs?

Answers (1)

KSSV
KSSV on 19 Jan 2022
You can get the wanted information from histogram.
Example:
x = randn(1,100) ; % random data for demo
h = histogram(x)
h =
Histogram with properties: Data: [-1.3555 0.7552 1.0002 -1.8729 -0.6261 0.4673 -0.4979 -0.5176 1.1454 -1.2476 1.6000 1.2608 0.5668 -0.1758 0.7651 -0.2759 -0.9973 -0.5760 -1.3655 1.2396 -0.5806 0.6480 0.0356 -0.6146 0.3910 -0.4373 -0.6452 1.4512 -0.0810 1.4027 … ] Values: [3 10 20 16 21 14 12 4] NumBins: 8 BinEdges: [-2 -1.5000 -1 -0.5000 0 0.5000 1 1.5000 2] BinWidth: 0.5000 BinLimits: [-2 2] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties
% fraction of total observations over each interval
h.Values/length(x)
ans = 1×8
0.0300 0.1000 0.2000 0.1600 0.2100 0.1400 0.1200 0.0400
  3 Comments

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!