How do I align decimal points in a table?

조회 수: 4 (최근 30일)
Bharath Lohray
Bharath Lohray 2017년 7월 12일
댓글: Les Beckham 2023년 2월 14일
Here is a sample of my data. I would like to align the decimal points to make it easy to read. How do I do this?
Entropy Min Max std
_______ _________ _______ ________
xyz_z 6.2908 0.0060019 0.83143 0.15786
xyz_y 6.2812 0.011033 0.81358 0.17433
xyz_x 6.1703 0.016483 0.76458 0.16028
RGB_B 5.6583 0 0.89412 0.13687
RGB_G 5.6379 0.062745 0.91373 0.15714
RGB_R 5.5792 0 0.94118 0.17313
Gray_WA 5.5706 0.086455 0.91075 0.15458
NTSC_Y 5.5706 0.086455 0.91075 0.15458
Gray_A 5.5398 0.11111 0.8902 0.14837
HSV_V 5.5371 0.21961 0.94118 0.11085
YCbCr_Y 5.3517 0.13699 0.84492 0.13275
HSV_S 5.0647 0 1 0.17222
HSV_H 4.6601 0 0.99858 0.10478
NTSC_I 3.5758 -0.2332 0.37468 0.053372
YCbCr_Cr 3.2791 0.32766 0.74433 0.034347
YCbCr_Cb 3.2367 0.1561 0.7043 0.033095
NTSC_Q 0.55185 -0.20632 0.12336 0.023349

답변 (4개)

Les Beckham
Les Beckham 2023년 2월 13일
편집: Voss 2023년 2월 14일
I think I found a solution. Use the Figure Space
s = compose('%10.4f', 50*rand(5,1));
snew = cellfun(@(c) strrep(c, ' ', char(0x2007)), s, 'UniformOutput', false)
fig = uifigure;
uit = uitable(fig, 'Data', snew)
Result
  댓글 수: 7
Les Beckham
Les Beckham 2023년 2월 14일
Of course it should. Thanks for catching that, Walter.
Les Beckham
Les Beckham 2023년 2월 14일
@Voss Thanks for the edit. I guess I should have done that. Mea culpa.

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


Star Strider
Star Strider 2017년 7월 12일
Applying a particular format to a table does not appear to be an option. It does not even inherit the current format setting.

Walter Roberson
Walter Roberson 2017년 7월 12일
If that is a table() object then you will need to convert the entries to strings using whatever formatting rules you find appropriate, such as '%10.7f'
table() objects have no format controls.

Matt O'Brien
Matt O'Brien 2023년 2월 13일
편집: Matt O'Brien 2023년 2월 13일
I have used a formatting string as indicated, but :
the numbers are now strings and ..... aligns left. This might be ok, but it also suppresses leading spaces, leaving a messy non aligned column of data.
Is there a workaround.
Can I replace leading spaces with some other non display char.
My own pet peeve here is that there is no option to set alignment within the screen layout gui. This is a basic requirement.
Here is a table. The third column is created using the following code to create a column and adding this column then to the table.
MyTestString(x,1) = sprintf('%10.3f',MyTable.MyDecimals(x));
Note... how the leading spaces are removed... thus rendering the exercise futile.
  댓글 수: 13
Matt O'Brien
Matt O'Brien 2023년 2월 14일
Thanks for the links. They will be useful when I explore style options later.
In the interim, I have replaced leading spaces with the 'Figure Space' char (and added a Figure Space after the number to provide spacing before the right hand border) to achieve the following.
I see I need to tidy up other alignment elements (such as the Column Titles and the Count Column)... but can do that when I have more spare time.
Again, I appreciate all the valueable ideas to help me solve this thorny issue.

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

카테고리

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