Decimals selection in pie charts

7 visualizaciones (últimos 30 días)
Erg
Erg el 11 de Oct. de 2017
Comentada: Walter Roberson el 23 de Mayo de 2018
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)

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Oct. de 2017
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 comentarios
Mats Burgmans
Mats Burgmans el 23 de Mayo de 2018
I get this error when using your code: Undefined function or variable 'numestr'.
Walter Roberson
Walter Roberson el 23 de Mayo de 2018
num2str

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Pie Charts en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by