How to make a weighted histogram with specific bins?
Show older comments
I'm new and I use MATLAB 2011.
I have a column of data and another column of weights:
d = [33 11 18 ... ] %data
w = [1 0.5 1 ...] %weights
There are only 11 possible values of my data so there would be 11 bins, I need to know the frequency count of each value.
I got a plot to work nicely WITHOUT including the weights by changing the data to ordinal:
bins = [0 11 12 13 14 15 16 17 18 32 33];
counts = droplevels(ordinal(d,[],bins));
hist(counts);
set(gca,'XTick',1:11);
I changed it to ordinal because otherwise, the bars had large spaces between them (because the x-axis ranged from 0-33) or merged together (clumped 11-18 together as one). I tried so many things, I couldn't list them all here.
The point is I need a plot to INCLUDE the weights in the frequency counts. I assume it can't be ordinal so the above code is irrelevant. I've done a lot of googling, everything I tried hasn't worked.
Any help is appreciated it, sorry if I'm confusing.
3 Comments
Shashank Prasanna
on 11 Jul 2013
How do you want to include the weights?
Jaclyn
on 11 Jul 2013
dpb
on 11 Jul 2013
So
length(w) == length(unique(data))
???
Accepted Answer
More Answers (0)
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!