How do I make a histogram using value - count pairs?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a 50027x2 matrix, M.
M(line, 2) is the amount of times the value M(line, 1) appeared on my problem.
In other words, instead of making a histogram using an array like [1 1 1 1 2 2 2 3], I'd like to get the same result through a matrix that looks like this:
[1 4;
2 3;
3 1]
I can plot it just fine, but for my assignment I need to make a histogram. Converting the matrix into an array by repeating the elements is not possible, since, for my M matrix, I'd need an array of 6,654,651,016 elements.
0 commentaires
Réponse acceptée
dpb
le 29 Déc 2020
Modifié(e) : dpb
le 29 Déc 2020
histogram('categories',categorical(M(:,1)),'bincounts',M(:,2))
to match the number of elements in x,y.
Otherwise, have to set the 'BinEdges' vector and it has to have length one greater than length of the counts vector.
See
doc histogram
for more details.
7 commentaires
dpb
le 30 Déc 2020
Hmmm....both worked here. Oh! Headslap! I used a test case with evenly divisible number of elements; if not have to round the divisor to have an integer spacing--
hAx.XTick=hAx.XTick([1:ceil(numel(hAx.XTick)/10):end end]);
Side note: In future please cut 'n paste the text of the message from the screen instead of using screenshots -- then folks don't have to go look somewhere else to see the message...
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!