How to create a histogram to count specific matrix element pairs?
1 view (last 30 days)
Show older comments
I have a 100x2 matrix that corresponds to a set of demographic data about a sample population. The first column contains either one of two possible values (1 or 2, to represent male/female genders), and the second column contains one of five possible values (to represent five income brackets). Each row represents the demographic characteristics of one person in my 100-person population. I understand how to make two histograms that each represent either the distribution of gender or the distribution of income, but I cannot seem to figure out how to make a histogram that counts the number of females ("2") with a particular income. How do I configure my histogram to consider two elements at once?
0 Comments
Accepted Answer
Image Analyst
on 9 Feb 2015
Try this:
men = data(:,1) == 1
menCounts = histc(data(men, 2), 1:5)
women = data(:,1) == 2
womenCounts = histc(data(women, 2), 1:5)
0 Comments
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!