how can i display only two decimals in uitable MATLAB?

36 次查看(过去 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')

回答(2 个)

dpb
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.

aamir ibrahim
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.

类别

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