How do I align decimal points in a table?

15 views (last 30 days)
Bharath Lohray
Bharath Lohray on 12 Jul 2017
Commented: Les Beckham on 14 Feb 2023
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

Answers (4)

Les Beckham
Les Beckham on 13 Feb 2023
Edited: Voss on 14 Feb 2023
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 Comments
Les Beckham
Les Beckham on 14 Feb 2023
Of course it should. Thanks for catching that, Walter.
Les Beckham
Les Beckham on 14 Feb 2023
@Voss Thanks for the edit. I guess I should have done that. Mea culpa.

Sign in to comment.


Star Strider
Star Strider on 12 Jul 2017
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 on 12 Jul 2017
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 on 13 Feb 2023
Edited: Matt O'Brien on 13 Feb 2023
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 Comments
Matt O'Brien
Matt O'Brien on 14 Feb 2023
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.

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!