MATLAB: How to extract column name of table in matlab

column nameextracttable

Can you suggest me a way to extract name of specific column of table in Matlab environment (as string)?

Best Answer

If you refer to 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'
If you refer to 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'