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']};
回答 (1 件)
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 件のコメント
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 についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
