Filter löschen
Filter löschen

How to format cells of a uitable?

28 Ansichten (letzte 30 Tage)
AbelM Kusemererwa
AbelM Kusemererwa am 24 Jul. 2015
Kommentiert: Walter Roberson am 24 Jul. 2015
I have used codes to create uitable table and the numbers numbers displayed are in 4 decimal places. How can I change it to an integer or a 2 decimal place?

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 24 Jul. 2015
data=rand(3,4);
d=arrayfun(@(x) sprintf('%.2f\n',x),data,'un',0)
h=uitable('Data',d,'Units','norm', 'Position',[0,.75,1,.25]);
  1 Kommentar
Walter Roberson
Walter Roberson am 24 Jul. 2015
One thing to note about this is that it makes the entries in the table into strings rather than numeric values. uitable() does not have any mechanism for formatting numeric entries other than is provided for by the ColumnFormat property which allows 'short', 'long', 'bank' and the other items permitted by the format() command. To go beyond those you need to output strings to the uitable. If you later use the uitable to compute with, be sure to convert back from strings to numeric form.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by