How can I assign a variable name to each column of a table composed by only one matrix?
107 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adriano
el 17 de Nov. de 2016
Respondida: Peter Perkins
el 18 de Nov. de 2016
I have a matrix that I can`t divide in vectors one by one (because it has 130 columns). For exemple, if I have:
A = [1 2 3; 4 5 6;]
I would create a table with different names for each column 1, 2 and 3, like:
Name1 Name2 Name3
_____ _____ _____
1 2 3
4 5 6
How can I do it? Thanks!
0 comentarios
Respuesta aceptada
Guillaume
el 17 de Nov. de 2016
array2table(A, 'VariableNames', {'Name1', 'Name2', 'Name3'})
0 comentarios
Más respuestas (1)
Peter Perkins
el 18 de Nov. de 2016
Presumably you've discovered that array2table already does that...
>> A = [1 2 3; 4 5 6]
A =
1 2 3
4 5 6
>> T = array2table(A)
T =
A1 A2 A3
__ __ __
1 2 3
4 5 6
... and the question you're really asking is, "how do I create names that are not based on the workspace variable's name?" Guillaume's response is one way, another would be to create the table and then assign to T.Properties.VariableNames.
0 comentarios
Ver también
Categorías
Más información sobre Logical 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!