convert variable to table header
조회 수: 23 (최근 30일)
이전 댓글 표시
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
Peter Perkins
2018년 10월 31일
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.
답변 (2개)
VBBV
2022년 2월 23일
편집: VBBV
2022년 2월 24일
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
Peter Perkins
2022년 3월 2일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!