how can i display only two decimals in uitable MATLAB?

36 ビュー (過去 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by