how can i display only two decimals in uitable MATLAB?
34 次查看(过去 30 天)
显示 更早的评论
Hi, i have a table in a subplot having also three histograms. I want to display in the table only two decimals and i don't know how to do it. This is my code:
clear; close all;
load('data')
.....
h = subplot(2,2,4);
hPos = get(h, 'Position');
tt = {'average';'standard dev.'; '% no rebound'};
MAC = [mean_MAC; std_MAC; mean_perc_zero_MAC]; % here
OMT= [mean_OMT; std_OMT; mean_perc_zero_OMT];
ACC = [mean_ACC; std_ACC; mean_perc_zero_ACC];
T = table(MAC,OMT,ACC,'RowNames',tt);
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position', hPos);
set(h, 'Visible', 'Off')
0 个评论
回答(2 个)
dpb
2019-7-12
Don't have that much flexibility with numeric formattting in the object, sorry.
uitable uses the same setting as the command window for its 'numeric' keyword. You could set the 'ColumnFormat' to the string 'Bank' that does use two decimal places as the easiest workaround.
Seems like reasonable enhancement request; I have no idea how complicated it would be to implement a general formatting facility to set '%.2f', for example, as to whether there would be any chance at all of such being ever implemented.
The alternative is to write a CellEditCallback function and format the data as desired but then display it as character string, not numeric.
0 个评论
aamir ibrahim
2024-2-26
Round off the numbers to the desired value. e.g. x = round(x,2) to two decimal places. Convert to string using string(x). This worked for me.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!