How can I concatenate tables vertically?

210 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 4 de Jul. de 2019
Editada: MathWorks Support Team el 13 de Oct. de 2022
How can I concatenate two or more tables vertically if they have the same headers?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 13 de Oct. de 2022
Editada: MathWorks Support Team el 13 de Oct. de 2022
To concatenate two or more tables vertically, you can use "vertcat" either as a function or as an operator - just as you would do to vertically concatenate two or more arrays. The headers do not even need be in the same order. Here is an example:
myTable1 = array2table(eye(3));
myTable1.Properties.VariableNames = ["One","Two","Three"];
myTable2 = array2table(2*eye(3));
myTable2.Properties.VariableNames = ["Two","Three","One"];
myTable3 = array2table(3*eye(3));
myTable3.Properties.VariableNames = ["Three","One","Two"];
myTable = [ myTable1; myTable2; myTable3 ]
The documentation page for "vertcat" explains that this function accepts table inputs:
  1 comentario
Stephen23
Stephen23 el 11 de Jul. de 2019
Editada: Stephen23 el 11 de Jul. de 2019
"...if I could create the 10 tables within a loop."
N = 10;
C = cell(1,N);
for k = 1:N
C{k} = table(...)
end
vertcat(C{:})
Although most likely you would be better off using one table, as they are specifically designed to group data and process those groups, without requiring separate tables.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by