plotting a pie chart

7 ビュー (過去 30 日間)
AngelsaAtWar
AngelsaAtWar 2013 年 4 月 10 日
コメント済み: MUHAMMAD NASEER 2020 年 5 月 1 日
Hi I am Having trouble getting this chart to come up, I want to plot a pie chart showing the name of the country and what piece of the pie it takes up, this is my code so far..
countries= [ US Mexico Canada Cuba Guatemala DominicanRepublic ElSalvador];
pop= [309975000 108396211 34207000 11204000 14377000 10225000 6194000];
total= sum(pop);
percentage= pop/total;
% Create a pie chart with sections 3 and 6 exploded figure;
explode = [0 0 1 0 0 1 0 0];
pie(percentage, explode, countries);
% Add title
title('Populations');
Thank you
  1 件のコメント
AngelsaAtWar
AngelsaAtWar 2013 年 4 月 10 日
It keeps giving me an error on the first set of data...the names

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2013 年 4 月 11 日
This works (although will need some refinement, which will be obvious when you run the code).
I did a couple things. I converted your countries variable to a cell array. Also, your explode variable was length 8, so I arbitrarily took off the last zero.
countries= {'US','Mexico','Canada','Cuba','Guatemala','Dominican Republic','El Salvador'};
pop= [309975000 108396211 34207000 11204000 14377000 10225000 6194000];
total= sum(pop);
percentage= pop/total;
% Create a pie chart with sections 3 and 6 exploded figure;
explode = [0 0 1 0 0 1 0];
pie(percentage, explode, countries);
% Add title
title('Populations');
  2 件のコメント
AngelsaAtWar
AngelsaAtWar 2013 年 4 月 11 日
thank you, I see now, I appreciate it and good catch on the extra variable in the expolde. I probably would have never caught it
MUHAMMAD  NASEER
MUHAMMAD NASEER 2020 年 5 月 1 日
still this code does not run

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by