convert variable to table header
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a column of data I would like convert to the header of a table
ans = May-2014
Jun-2014
Jul-2014
Aug-2014
Sep-2014
Oct-2014
Nov-2014
Dec-2014
Jan-2015
Feb-2015
Mar-2015
Apr-2015
May-2015
Jun-2015
Jul-2015
Aug-2015
Sep-2015
Oct-2015
Nov-2015
Dec-2015
Jan-2016
Feb-2016
Mar-2016
Apr-2016
May-2016
Jun-2016
Jul-2016
Aug-2016
Sep-2016
Oct-2016
Nov-2016
Dec-2016
Jan-2017
Feb-2017
Mar-2017
Apr-2017
May-2017
Jun-2017
Jul-2017
Aug-2017
Sep-2017
Oct-2017
Nov-2017
Dec-2017
Jan-2018
Feb-2018
Mar-2018
Apr-2018
May-2018
Jun-2018
Jul-2018
Aug-2018
Sep-2018
1 Kommentar
Peter Perkins
am 31 Okt. 2018
It's not clear what you mean by "header" or "table". If you mean the variable names of a MATLAB table, those need to be unique and valid MATLAB identifiers, so they can't contain a dash.
Antworten (2)
VBBV
am 23 Feb. 2022
Bearbeitet: VBBV
am 24 Feb. 2022
names = {'May-2014','Jun-2014','Jul-2014','Aug-2014'}
T1 = rand(10,1);
T2 = T1;
T3 = T2;
T4 = T3;
T = table(T1,T2,T3,T4,'VariableNames',names)
Convert the column into cell array. And use it in table with VariableNames argument.
1 Kommentar
Peter Perkins
am 2 Mär. 2022
Correct, support for "arbitrary" variable names was a change made a couple years ago. The benefit is you can name variables almost anything. The drawback is you can't say t.May-2014 (for obvious reasons), you must say t.("May-2014").
The large print giveth and the small print taketh away.
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!