How to make vector of strings into column headers of table

조회 수: 9 (최근 30일)
Danny
Danny 2014년 10월 25일
댓글: Danny 2014년 10월 25일
I have a vector of dates:
a =
Oct_2014
Nov_2014
Dec_2014
and I want to use the array2table function to make a table with these dates as the column headers:
array2table([10 12 14],'VariableNames',a).
It will work if a = {'Oct_2014' 'Nov_2014' 'Dec_2014'} but does not as given above. How do I go from the first instance of 'a' to the second?

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 10월 25일
a = {'Oct_2014' ;'Nov_2014' ; 'Dec_2014'}
b=array2table([10 12 14],'VariableNames',a)
  댓글 수: 5
Guillaume
Guillaume 2014년 10월 25일
Of course, a is the name of the variable. We need to know its type, as it's not obvious from your statements. It could be a char array, a cell array of string, or something else.
whos a
will tell us for sure.
If, in matlab, you write
a =
Oct_2014
Nov_2014
Dec_2014
you'll get a syntax error. So, from your statement, we don't know what a is
Danny
Danny 2014년 10월 25일
Thank you. I was able to figure this out as 'a' was a char vector and I needed it as a string vector so I used the function cellstr.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by