How do I make a histogram using value - count pairs?

조회 수: 15 (최근 30일)
Tomé Carvalho
Tomé Carvalho 2020년 12월 29일
댓글: Tomé Carvalho 2020년 12월 30일
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.

채택된 답변

dpb
dpb 2020년 12월 29일
편집: dpb 2020년 12월 29일
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
dpb
dpb 2020년 12월 30일
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...
Tomé Carvalho
Tomé Carvalho 2020년 12월 30일
Thanks, it worked now. Hopefully there won't be a next time!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by