How to format cells of a uitable?

조회 수: 30 (최근 30일)
AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 24일
댓글: Walter Roberson 2015년 7월 24일
I have used codes to create uitable table and the numbers numbers displayed are in 4 decimal places. How can I change it to an integer or a 2 decimal place?

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 24일
data=rand(3,4);
d=arrayfun(@(x) sprintf('%.2f\n',x),data,'un',0)
h=uitable('Data',d,'Units','norm', 'Position',[0,.75,1,.25]);
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 7월 24일
One thing to note about this is that it makes the entries in the table into strings rather than numeric values. uitable() does not have any mechanism for formatting numeric entries other than is provided for by the ColumnFormat property which allows 'short', 'long', 'bank' and the other items permitted by the format() command. To go beyond those you need to output strings to the uitable. If you later use the uitable to compute with, be sure to convert back from strings to numeric form.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by