currently some of my Uitable is decimal and some is scientific notation. I would like to make it all decimal and be able to control the number of decimal places. Anyone know how to set the output to decimal and be able to change the number of decimals in the context of my code? (below)
f = figure('Position',[1 1 500 250]);
%Row and column names
cnames = {'C1','C2'};
rnames = {'R1','R2','R3'...
'R4', 'R5', 'R6'...
'R7','R8',...
'R9', 'R10'...
'R11' };
% create the data
d = [SmI SmD ; RmI RmD ; KmI KmD ; RthI RthD;QjthI QjthD;...
QjthISS QjthDSS;QpcI QpcD; QpcISS QpcDSS; QphI QphD;...
QphISS QphDSS;ZmI ZmD];
% Create the uitable
t = uitable('Data',d,...
'ColumnName',cnames,...
'RowName',rnames);
% Set width and height
tableextent = get(t,'Extent');
oldposition = get(t,'Position');
newposition = [oldposition(1) oldposition(2) tableextent(3)...
tableextent(4)];
set(t, 'Position', newposition);

댓글 수: 1

Jelthe
Jelthe 2016년 3월 23일
Nobdy? I got the same problem. It might just be writing '%.2f' somewhere. But i cant figure out where.

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

 채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 23일
편집: Walter Roberson 2025년 2월 3일

0 개 추천

There is no control of the individual numeric entries other than...
ColumnFormat: "A string accepted by the format function, such as: 'short', 'bank', 'long'"
For anything more complex than that you need to convert the numeric entries to strings and display the strings.

댓글 수: 3

Lee
Lee 2022년 10월 5일
I cannot find any documentation regarding these column format options - are they now obsolete?
So in 6 years, Matlab still haven't added the ability to control decimation in a uitable?
Walter Roberson
Walter Roberson 2025년 2월 3일
Thanks for the URL update,, @Pierre Harouimi

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

추가 답변 (1개)

Allen Daubendiek
Allen Daubendiek 2018년 8월 23일

0 개 추천

Building on Walter's answer, I found reformatting data in a cell string useful.
Try a variation of this (left pad each string to 9 characters):
d = cellstr( pad( string( d ), 9, 'left' ) );
uitable( gcf, 'Data', d, 'ColumnFormat',{'char', 'char'} );
This solution will break down at some point for picky users, but it improved my aesthetics in the short term.

댓글 수: 5

You might also want to switch the font to fixed width.
Another way of getting the padded cells is
d = sprintfc('%9.2f', NumericArray);
Lee
Lee 2022년 10월 5일
편집: Lee 2022년 10월 5일
why do neither of these methods work when using a table in app designer?
If i create a new figure with table: uitable(gcf, 'Data', d) i see the numbers being pushed to the right. However, if I add a table to my GUI: uitable(app.tab, 'Data', d) the numbers remain left aligned
So even after doing all the adjustments I need with sprintf, the table in my app doesn't look as I want!
Walter Roberson
Walter Roberson 2022년 10월 5일
uitable() for uifigure() have a different implementation and slightly different properties than uitable() for traditional figure()
Lee
Lee 2022년 10월 6일
ok thanks, I will give a try. What a complete mess though...
Nieves
Nieves 2025년 2월 21일
Just something further on this. I was able to convert to strings, and that looked perfect. However, the sort order was then broken.

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

카테고리

도움말 센터File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품

질문:

Al
2015년 1월 19일

댓글:

2025년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by