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)

 Réponse acceptée

Walter Roberson
Walter Roberson le 11 Oct 2017

0 votes

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 commentaires

Mats Burgmans
Mats Burgmans le 23 Mai 2018
I get this error when using your code: Undefined function or variable 'numestr'.
Walter Roberson
Walter Roberson le 23 Mai 2018
num2str

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by