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개)

카테고리

도움말 센터File Exchange에서 Pie Charts에 대해 자세히 알아보기

제품

질문:

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