convert variable to table header

23 visualizzazioni (ultimi 30 giorni)
Lekebis Russell
Lekebis Russell il 23 Ott 2018
Commentato: Peter Perkins il 2 Mar 2022
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 Commento
Peter Perkins
Peter Perkins il 31 Ott 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.

Accedi per commentare.

Risposte (2)

madhan ravi
madhan ravi il 23 Ott 2018

VBBV
VBBV il 23 Feb 2022
Modificato: VBBV il 24 Feb 2022
names = {'May-2014','Jun-2014','Jul-2014','Aug-2014'}
names = 1×4 cell array
{'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)
T = 10×4 table
May-2014 Jun-2014 Jul-2014 Aug-2014 ________ ________ ________ ________ 0.040758 0.040758 0.040758 0.040758 0.4251 0.4251 0.4251 0.4251 0.73176 0.73176 0.73176 0.73176 0.57194 0.57194 0.57194 0.57194 0.27224 0.27224 0.27224 0.27224 0.41762 0.41762 0.41762 0.41762 0.78178 0.78178 0.78178 0.78178 0.60934 0.60934 0.60934 0.60934 0.53484 0.53484 0.53484 0.53484 0.64737 0.64737 0.64737 0.64737
Convert the column into cell array. And use it in table with VariableNames argument.
  1 Commento
Peter Perkins
Peter Perkins il 2 Mar 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.

Accedi per commentare.

Categorie

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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by