Effacer les filtres
Effacer les filtres

How to make histogram with volume instead of frequency?

8 vues (au cours des 30 derniers jours)
Jemima Puddleduck
Jemima Puddleduck le 20 Juin 2016
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.

Réponses (2)

the cyclist
the cyclist le 20 Juin 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 commentaire
Jemima Puddleduck
Jemima Puddleduck le 21 Juin 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.

Connectez-vous pour commenter.


the cyclist
the cyclist le 22 Juin 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.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by