How to extract column name of table in matlab

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

Risposta accettata

Michael Haderlein
Michael Haderlein il 5 Feb 2015
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'
  4 Commenti
Alex Whiteway
Alex Whiteway il 20 Mag 2021
Modificato: Alex Whiteway il 20 Mag 2021
>> T.Properties.VariableNames{2}
ans =
'Age'

Accedi per commentare.

Più risposte (1)

Vencel Kozma
Vencel Kozma il 2 Dic 2022
You could also use only these 2 lines:
excel_struct = table2struct(excel_table);
SelectedColumn_var = extractfield(excel_struct, 'SelectedColumn')';

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by