Decimals selection in pie charts

Hi! I'm trying to choose the number of decimals in the chart, but couldn't find anything in the documentation. Does anyone know how to do it? For example, how to do it on the following simple case? It always returns the approximation 10% and 90%, but I need an higher precision: 10.1% and 89.9%. Thank you!
x = [0.101 .899];
pie(x)

 採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 11 日

0 投票

The code internally uses an integer format for the values multiplied by 100%, so there is no way to tell it to just use more decimal places.
However, you can pass a cell array of character vectors as the second element of pie(), and those will be used as the labels. You can construct that cell array of character vectors.
percent = x(:) ./ sum(x(:)) * 100;
labels = cellstr( numestr( percent, '%.1f%%' ) ); %relies on percent being a column vector
pie(x, labels);

2 件のコメント

Mats Burgmans
Mats Burgmans 2018 年 5 月 23 日
I get this error when using your code: Undefined function or variable 'numestr'.
Walter Roberson
Walter Roberson 2018 年 5 月 23 日
num2str

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

その他の回答 (0 件)

カテゴリ

製品

質問済み:

Erg
2017 年 10 月 11 日

コメント済み:

2018 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by