how can i display only two decimals in uitable MATLAB?

조회 수: 34 (최근 30일)
EM geo
EM geo 2019년 7월 12일
답변: aamir ibrahim 2024년 2월 26일
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에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by