How do I extract column name of table in MATLAB?

1,694 次查看(过去 30 天)
Can you suggest me a way to extract name of specific column of table in MATLAB?

采纳的回答

Michael Haderlein
Michael Haderlein 2024-5-15
编辑:MathWorks Support Team 2024-6-5
If you refer to "table": 
LastName = ["Sanchez";"Johnson";"Li";"Diaz";"Brown"];
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
T = table(LastName,Age,Smoker);
>> T.Properties.VariableNames
ans =
1×3 cell array
{'LastName'} {'Age'} {'Smoker'}
>> T.Properties.VariableNames{2}
ans =
'Age'
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]);
>> get(t,"columnname")
ans =
3×1 cell array
{'X-Data'}
{'Y-Data'}
{'Z-Data'}
  4 个评论

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by