legend pie chart

5 views (last 30 days)
franz
franz on 19 Jan 2012
Hi i'm new to matlab and i have a question. for example if i have a vector with some ascii numbers, like
x=[65 65 67 68 68 68 68]
and i then want to draw a pie chart with the most frequent letter.
x=[65 65 67 68 68 68 68]
char(x)
y=unique(x)
counts=histc(x,y)
pie(counts,cellstr(num2str(counts(:))))
but my problem is that i want to have a legend witch will say what letter the different coulors represents, is that possible?
  1 Comment
the cyclist
the cyclist on 19 Jan 2012
Really an aside to your question, but you would probably want to use hist() rather than hist(), because you are specifying the bins, not the edges between the bins.
Also, I would recommend against a pie chart here. A bar chart will most likely allow the consumer to better judge the relative letter frequency.

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 19 Jan 2012
Like this?
x=[65 65 67 68 68 68 68];
y=unique(x);
counts=histc(x,y);
pie(counts,cellstr(char((y')))')
Note transpose for num2str()
  11 Comments
Sean de Wolski
Sean de Wolski on 19 Jan 2012
legend(cellstr(char((y')))')
franz
franz on 19 Jan 2012
Yes that worked thanks!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!