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

14 次查看(过去 30 天)
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 个评论
Eric Sofen
Eric Sofen 2023-12-18
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 2023-12-18
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.

请先登录,再进行评论。

回答(1 个)

Drishti
Drishti 2024-9-20,11:42
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.

类别

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