필터 지우기
필터 지우기

Creating table: how to define variable names

조회 수: 163 (최근 30일)
turquoise_squid
turquoise_squid 2016년 5월 5일
편집: Deborah 2019년 7월 15일
How can I define Variable names for each column after creating a table from a single variable with several columns?
For instance, when creating a table from one matrix x, MATLAB defines one name for the whole matrix irrespective of its column size. The only way to circumvene this problem is to subdefine each column of the matrix as a seperate variable. In my case I have go a matrix with 150 columns and it is very time consuming to do it this way:
table(x(:,1),x(:,2),..., x(:,150), 'VariableNames',{'Gender' 'Age' ... 'Sex'})
thank you for your assistance!

답변 (2개)

Guillaume
Guillaume 2016년 5월 5일
편집: Guillaume 2016년 5월 5일
The way to circumvent this problem is to use the proper function to create a table from a matrix which is array2table (see also cell2table and struct2table):
t = array2table(x)

Deborah
Deborah 2019년 7월 15일
편집: Deborah 2019년 7월 15일
I have however noticed that you may have to use the exact names of the column vectors you are passing to the 'table' function for that to work. For example:
Gender = x(:,1); Age = x(:,2);
T = table(Gender,Age,'VariableNames',{'Gender','Age'})
Note that you can only use array2table when the array entries are homogenous, but the above works for mixed entries (for example if Gender is a column vector of strings while Age is a numeric column vector).

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by