Pie chart help

조회 수: 4 (최근 30일)
Njöng
Njöng 2011년 12월 6일
Let´s say I have a vector x = [1 1 2 2 2 3 3 3 3] I want to make a pie chart that shows the frequency of each number. In this case, it would be divided into three slices and the slice representing number 3 would be the biggest etc. Is that possible? Thanks in advance. /Njööööng

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 6일
More specifically: use hist() or histc() to count the number of items of each type and pass that count vector to pie as the X value. Pass text representations of each element in the labels parameter.
e.g.,
u = unique(x);
counts = histc(x, u);
pie(counts, cellstr(num2str(u(:))) )
  댓글 수: 4
Walter Roberson
Walter Roberson 2011년 12월 6일
num2str() fixed.
Njöng, notice that I did not pie(x), I used pie(counts) where counts is the result of the histc(). There would be 3 values in count so there would be 3 slices, each with area proportional to the _number_ of values in that bin.
Njöng
Njöng 2011년 12월 8일
Sorry, young man, I mustve misread your post, Im an old lady, you see :)
Next question: Is there a way to insert a legend and label the slices?

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

카테고리

Help CenterFile Exchange에서 Pie Charts에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by