round two decimal in table app designer

24 Ansichten (letzte 30 Tage)
pipin
pipin am 4 Aug. 2023
Kommentiert: pipin am 5 Aug. 2023
[app.UITableFilteredTable.Data]=Table_HistoricalTable_Struct(app.Eq);
x = [{90} repmat({60},1,size(app.UITableFilteredTable.Data,2)-1)];
app.UITableFilteredTable.ColumnWidth =x;
app.UITableFilteredTable.ColumnName ={};
i try to use : round(v*100)/100 in table field's but it doesn't work

Akzeptierte Antwort

Voss
Voss am 4 Aug. 2023
A random matrix:
M = rand(10,2);
A uitable showing that matrix (defaults to 4 decimal places):
figure()
uitable('Data',M);
Another uitable with the numbers rounded to two decimal places:
figure()
uitable('Data',round(M,2));
Another uitable with rounded data, using character vectors instead of numbers:
figure()
t = uitable('Data',compose('%.2f',M),'ColumnFormat',{'char','char'});
Since you are using a uifigure, you can also add a uistyle to the uitable that sets the HorizontalAlignment of the text to the right.
s = uistyle('HorizontalAlignment','right');
addStyle(t,s)
  6 Kommentare
Voss
Voss am 5 Aug. 2023
Yes
t = app.UITableFilteredTable; % your uitable
s = uistyle('HorizontalAlignment','center') % 'center' or whatever you want them to be
addStyle(t,s,'column',[1 3:size(t.Data,2)]) % add style s to columns 1 and 3:end of uitable t
pipin
pipin am 5 Aug. 2023
thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by