how can I get together 2 tables containing different number of rows and colomns?
8 ビュー (過去 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
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
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
2024 年 9 月 20 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!