필터 지우기
필터 지우기

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

조회 수: 14 (최근 30일)
Okan Erisen
Okan Erisen 2023년 12월 18일
답변: Drishti 2024년 9월 20일 11:42
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