How to create a histogram to count specific matrix element pairs?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hayat
am 9 Feb. 2015
Beantwortet: Image Analyst
am 9 Feb. 2015
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!