how to merge tables without any common keywords?
2 次查看(过去 30 天)
显示 更早的评论
I have a 20*20,a 20*1 and a 1*20 tables. I would like add the last two tables into the first one and become a 21*21 table. However all of the three tables are exactly numeric and do not have name for rows and columns and no common keywords.
回答(1 个)
BhaTTa
2024-7-26
To add the 20x1 and 1x20 tables to the 20x20 table to create a 21x21 table in MATLAB, you can follow these steps:
- Create the initial tables:
- Let A be your 20x20 table.
- Let B be your 20x1 column vector.
- Let C be your 1x20 row vector.
- Expand the size of the original table:
- Initialize a new 21x21 matrix filled with zeros.
- Place the original 20x20 matrix A into the top-left corner of this new matrix.
- Add the 20x1 vector B as the last column of the new matrix.
- Add the 1x20 vector C as the last row of the new matrix.
- Make sure to place the bottom-right cell of the new matrix appropriately to avoid overwriting.
Here's how you can do this in MATLAB:
% Sample data (replace these with your actual data)
A = rand(20, 20); % 20x20 matrix
B = rand(20, 1); % 20x1 column vector
C = rand(1, 20); % 1x20 row vector
% Initialize a 21x21 matrix with zeros
D = zeros(21, 21);
% Place the 20x20 matrix A into the top-left corner
D(1:20, 1:20) = A;
% Add the 20x1 vector B as the last column (column 21)
D(1:20, 21) = B;
% Add the 1x20 vector C as the last row (row 21)
D(21, 1:20) = C;
% Add the bottom-right cell to complete the matrix (intersection point)
D(21, 21) = 0; % If you want to fill it with a specific value, replace 0 with that value
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!