how to merge tables without any common keywords?

12 次查看(过去 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 个评论
Walter Roberson
Walter Roberson 2024-7-26,5:14
编辑:Walter Roberson about 20 hours 前
I have to wonder whether table here refers to numeric matrices, or to table objects ?

请先登录,再进行评论。

回答(1 个)

BhaTTa
BhaTTa 2024-7-26,4:33
To add the 20x1 and 1x20 tables to the 20x20 table to create a 21x21 table in MATLAB, you can follow these steps:
  1. Create the initial tables:
  • Let A be your 20x20 table.
  • Let B be your 20x1 column vector.
  • Let C be your 1x20 row vector.
  1. 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

类别

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