Creating table: how to define variable names
150 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuestas (2)
Deborah
el 15 de Jul. de 2019
Editada: Deborah
el 15 de Jul. de 2019
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).
0 comentarios
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!