如何在uitable
中居中对齐一列(字符串和数字)?这是用于演示,因此可以通过在其上填充空格来“伪造”它。 (使用R2018a。)
% construct simple table as example %
t = array2table(zeros(4,1));
t.Properties.VariableNames{'Var1'} = 'id';
t.id(:) = 1;
t.fieldA = {'a'; 'b'; 'c'; 'd'};
t.GroupCount = [22; 1; 19; 0];
% plotting
f = figure;
uit = uitable(f, 'Data', table2cell(t));
uit.ColumnName={t.Properties.VariableNames{:}};
uit.RowName=[];
% test justification on the first column:
uit.ColumnFormat = {'numeric'}; % this right justifies
uit.ColumnFormat = {'char'}; % this left justifies
% how can I get it center justified?
类似于uit.ColumnFormat = {'%5s'};
,但无法传递此输入(以下错误);有没有办法欺骗它?
Error setting property 'ColumnFormat' of class 'Table':
ColumnFormat definitions must be either 'numeric', 'logical', 'char', 'short', 'long', 'short e', 'long e', 'short g', 'long g', 'short eng', 'long eng',
'bank', '+', 'rat' or be a popupmenu definition
这可以使用undocumented功能如下:
for k=1:numel(uit.Data)
uit.Data{k} =['<html><tr><td width=9999 align=center>',num2str(uit.Data{k})];
end