How do I extract column name of table in MATLAB?
1.692 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pafi Pafian
am 5 Feb. 2015
Bearbeitet: MathWorks Support Team
am 5 Jun. 2024
Can you suggest me a way to extract name of specific column of table in MATLAB?
0 Kommentare
Akzeptierte Antwort
Michael Haderlein
am 15 Mai 2024
Bearbeitet: MathWorks Support Team
am 5 Jun. 2024
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 Kommentare
Alex Whiteway
am 20 Mai 2021
Bearbeitet: Alex Whiteway
am 20 Mai 2021
>> T.Properties.VariableNames{2}
ans =
'Age'
Weitere Antworten (1)
Vencel Kozma
am 2 Dez. 2022
You could also use only these 2 lines:
excel_struct = table2struct(excel_table);
SelectedColumn_var = extractfield(excel_struct, 'SelectedColumn')';
0 Kommentare
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!