Table embedded in uitable ignores ColumnFormat Property

Any idea why a table embedded into a uitable control ignores the ColumnFormat property? In the example below, if I feed a cell array (data1 variable) to my uitable, I get the second column right-aligned, as desired. If I try the same thing with feeding a table to uitable as data (data2 variable), it obeys all of the other property commands except for ColumnFormat. Thoughts?
f = uifigure;
A = {'Test 1'; 'Test 2'};
B = {'1'; '2'};
data1 = [A, B];
data2 = table(A, B);
t = uitable(f);
% t.Data = data1;
t.Data = data2;
t.ColumnName = {'Coefficient'; 'Value'};
t.ColumnWidth = {99 99};
t.RowName = {};
t.RowStriping = 'off';
t.ColumnEditable = [false true];
t.ColumnFormat = {[] ['numeric']};

댓글 수: 2

Not only the alignment of numeric values differs but also the fontsize, row height, and header alignment. The image on the left is the cell input, the image on the right is table input.
190714 161139-.jpg
Indeed. The other stuff didn't bother me so much, mostly the alignment. Actually, the reason why I want to feed a table to uitable instead of an array is precisely because the row height is larger and more visually appealing to me.

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2019년 7월 14일
편집: Adam Danz 2019년 7월 15일
In your table "data2", the second column are not numeric values. They are of class char.
class(data2.B{1})
ans =
'char'
For whatever reason, even when you specify the column format as numeric, they are still treated as 'char' even through they are treated as numeric if you input a cell array (data1).
To fix the issue, use numeric values in your table.
A = {'Test 1'; 'Test 2'};
B = {1; 2};
data2 = table(A, B);
Or convert the values you already have
data2 = table(A,str2double(B));

댓글 수: 3

Jeremy
Jeremy 2019년 7월 14일
편집: Jeremy 2019년 7월 14일
I actually made the numbers into char's intentionally, because uitable was truncating my values when I kept them as numbers. See the example below, which uses the actual table values that started all of my problems. If you can figure out how to display the scientific notation data in scientific notation in the table, then my original question is no longer relevant to my needs.
f = uifigure;
A = {'ROC'; 'k'; 'a2'; 'a4'};
B = [12.8302; 0.2904; 0; 1.1254441e-05];
data2 = table(A, B);
t = uitable(f);
t.Data = data2;
t.ColumnName = {'Coefficient'; 'Value'};
t.ColumnWidth = {99 99};
t.RowName = {};
t.RowStriping = 'off';
t.ColumnEditable = [false true];
Jeremy
Jeremy 2019년 7월 14일
편집: Jeremy 2019년 7월 14일
Here's something that's weird. If you change the exponent on 1.1254441e-05 to 1.1254441e+05, it displays fine.
Adam Danz
Adam Danz 2019년 7월 14일
편집: Adam Danz 2019년 7월 17일
If your input is a cell array (data1 in your original example), you can set the ColumnFormat so that the numers are in sci notation or any other format listed here.
f = uifigure;
A = {'ROC'; 'k'; 'a2'; 'a4'};
B = {12.8302; 0.2904; 0; 1.1254441e-05};
data1 = [A, B];
t = uitable(f,'data',data1,'ColumnFormat',{[],'short g'});
t.ColumnName = {'Coefficient'; 'Value'};
t.ColumnWidth = {99 99};
t.RowName = {};
t.RowStriping = 'off';
t.ColumnEditable = [false true];
But for whatever reason, the ColumnFormat specification is ignored with table inputs. So unless there's an undocumented way to get around this, I'm not sure if you'll be able to have your cake (the Table input) and eat it, too (the sci notation).
As you discovered previously, you can always convert your numbers to string format and just use strings.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

질문:

2019년 7월 14일

편집:

2019년 7월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by