Clear Filters
Clear Filters

How to make histogram with volume instead of frequency?

8 views (last 30 days)
I have a column vector 'temp' with values of temperature, and an associated column vector 'vol' with values of volume. In other words, each temperature is associated with a volume.
I would like to create a histogram of temperature, BUT, instead of having each bin represent frequency, I would like it to represent volume fraction. (so, for example, the first bin might be 0ºc to 80ºc and have a value of 0.25, meaning 1/4 if the total volume has a temperature from 0ºc to 80ºc).
I am very new to Matlab, so I would appreciate a solution which is easy to understand and implement. Is what I'm looking for called a weighted histogram? Searching the forums for this term doesn't return much.

Answers (2)

the cyclist
the cyclist on 20 Jun 2016
From your description, it sounds like you don't need the calculation part of what a histogram calculates, and you already have the y value. If that is the case, then you can just use the bar function, like this
T = [1 2 3 4];
V = [0.25 0.15 0.40 0.20];
figure
bar(T,V)
  1 Comment
Jemima Puddleduck
Jemima Puddleduck on 21 Jun 2016
Thanks. Problems I can see with this solution are:
1) My data is unsorted. I suppose this is easily fixed by sorting.
2) Even with sorted data, each column vector has around 500,000 rows (should have stated in question, sorry). This solution would create around 500,000 bins. Is there some way to arrange the bar plot into 'bins' in a histogram fashion?
3) I need a log scale on the x-axis.

Sign in to comment.


the cyclist
the cyclist on 22 Jun 2016
Ah, from your comment on my other answer, I understand better. You might have had temps
T = [2, 12, 18, 27, 79]
that you need gathered together, and collectively they account for 0.25.
I can't write up a complete example right now, but you might be able to use the accumarray function to do this. It might not be simple to automate the binning part, though.

Products

Community Treasure Hunt

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

Start Hunting!