How to create a histogram to count specific matrix element pairs?

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?

 Réponse acceptée

Try this:
men = data(:,1) == 1
menCounts = histc(data(men, 2), 1:5)
women = data(:,1) == 2
womenCounts = histc(data(women, 2), 1:5)

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by