Как выровнять подходящие столбцы в matlab по центру? - PullRequest
0 голосов
/ 01 апреля 2020

Как можно выровнять по центру столбец (строки и числа) в 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

1 Ответ

0 голосов
/ 01 апреля 2020

Это можно сделать с помощью возможности без документов следующим образом:

for k=1:numel(uit.Data)
    uit.Data{k} =['<html><tr><td width=9999 align=center>',num2str(uit.Data{k})];
end

Результат:

...