how can I get together 2 tables containing different number of rows and colomns?

9 visualizaciones (últimos 30 días)
I have 2 tables. One of them is 2160x7 table and the other one is 9444x9 table. Each colomn of the tables has a different name. How can I get them together?
  3 comentarios
Eric Sofen
Eric Sofen el 18 de Dic. de 2023
We're going to need more detail about the contents of the tables and how you want to combine them. What are the commonalities between the tables? But, as @Stephen23 says, the join functions are a good place to start.
Cris LaPierre
Cris LaPierre el 18 de Dic. de 2023
I would recommend using the Join Tables Live Task to perform your join interactively. Once you find the settings that get you the result you want, you can convert the task to code.
Otherwise, please attach your data using the paperclip icon, as well as an example of what the output should be.

Iniciar sesión para comentar.

Respuestas (1)

Drishti
Drishti el 20 de Sept. de 2024
Hi Okan,
For combining tables with different number of rows and columns you can refer to the MATLAB ‘join’ function.
The ‘join’ function is applicable if you have common columns or key variables. If the tables do not have any common column and differ in size as well, you can use ‘NaN’ values to facilitate the merging of tables.
Refer to the below code snippet for better understanding:
% Determine the maximum number of rows
maxRows = max(height(table1), height(table2));
% Pad the shorter table with NaN rows
if height(table1) < maxRows
% Extend table1 with NaN
table1{end+1:maxRows, :} = NaN;
end
if height(table2) < maxRows
% Extend table2 with NaN
table2{end+1:maxRows, :} = NaN;
end
% Horizontally concatenate the tables
combinedTable = [table1, table2];
Refer to the MATLAB Documentation of ‘join’ function to understand its functionality.
I hope this resolves your query.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by