Uitable Decimal Places How To?
54 ビュー (過去 30 日間)
古いコメントを表示
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
2016 年 3 月 23 日
Nobdy? I got the same problem. It might just be writing '%.2f' somewhere. But i cant figure out where.
採用された回答
Walter Roberson
2016 年 3 月 23 日
There is no control of the individual numeric entries other than... http://www.mathworks.com/help/matlab/ref/uitable-properties.html#property_columnformat
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.
1 件のコメント
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?
その他の回答 (1 件)
Allen Daubendiek
2018 年 8 月 23 日
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.
4 件のコメント
Walter Roberson
2022 年 10 月 5 日
uitable() for uifigure() have a different implementation and slightly different properties than uitable() for traditional figure()
for uifigure() there is the StyleConfigurations property https://www.mathworks.com/help/matlab/ref/matlab.ui.control.table-properties.html?searchHighlight=uitable%20properties&s_tid=srchtitle_uitable%20properties_4#mw_7016c015-778b-48aa-bb90-a726d7f1010d and perhaps uistyle() would allow you to do the appropriate adjustment.
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!