representing data in pie chart

8 ビュー (過去 30 日間)
asaf omer
asaf omer 2021 年 4 月 11 日
回答済み: Monisha Nalluru 2021 年 4 月 14 日
hello everybody i wanna represent data in pie chart:
and i got stuck when the sum of values is less than 100:
a2=input("please enter numeric values using '[ ]' : ");
if sum (a2)>=100
pie(a2)
else
labels = {'data','Other'};
pie(sum(a2),100-sum(a2),labels)

回答 (1 件)

Monisha Nalluru
Monisha Nalluru 2021 年 4 月 14 日
pie(X) draws a pie chart using the data in X
  • If sum(X) ≤ 1, then the values in X directly specify the areas of the pie slices. pie draws only a partial pie if sum(X) < 1.
  • If sum(X) > 1, then pie normalizes the values by X/sum(X) to determine the area of each slice of the pie.
But if you dont want a partial pie when sum(X) < 100 you can use if condition and calculate the other variable value and plot it.
As an example
a2=input("please enter numeric values using '[ ]' : ");
if sum(a2)>100
disp('Invalid Entry: Sum Greater than 100');
elseif sum(a2) == 100
pie(a2);
else
others = 100 - sum(a2);
a2 = [a2, others];
pie(a2);
end
Hope this helps!

カテゴリ

Help Center および File ExchangePie Charts についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by