Pie chart help
Mostra commenti meno recenti
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
Risposte (1)
Walter Roberson
il 6 Dic 2011
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 Commenti
Njöng
il 6 Dic 2011
Sean de Wolski
il 6 Dic 2011
nice with cellstr! typo though, should be num2str
Walter Roberson
il 6 Dic 2011
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
il 8 Dic 2011
Categorie
Scopri di più su Pie Charts in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!