如何在matlab中提取table的列名

How to extract column name of table in matlab

你能建议我在 Matlab 环境中提取 table 的特定列的名称(作为字符串)吗?

答案如下: http://se.mathworks.com/matlabcentral/answers/175423-how-to-extract-column-name-of-table-in-matlab

对于 uitable:

f = figure('Position',[200 200 400 150]);
dat = rand(3); 
cnames = {'X-Data','Y-Data','Z-Data'};
rnames = {'First','Second','Third'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,... 
           'RowName',rnames,'Position',[20 20 360 100]); %from matlab help

get(t,'columnname')

ans = 

'X-Data'
'Y-Data'
'Z-Data'

对于 table:

T = table(['M';'F';'M'],[45;32;34],...
         {'NY';'CA';'MA'},logical([1;0;0]),...
         'VariableNames',{'Gender' 'Age' 'State' 'Vote'}); %from matlab help
T.Properties.VariableNames

ans = 

'Gender'    'Age'    'State'    'Vote'