Filter löschen
Filter löschen

how to merge tables without any common keywords?

12 Ansichten (letzte 30 Tage)
Taoli Li
Taoli Li am 18 Jan. 2016
Bearbeitet: Walter Roberson vor etwa 24 Stunden
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 Kommentar
Walter Roberson
Walter Roberson am 26 Jul. 2024 um 5:14
Bearbeitet: Walter Roberson vor etwa 24 Stunden
I have to wonder whether table here refers to numeric matrices, or to table objects ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

BhaTTa
BhaTTa am 26 Jul. 2024 um 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

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by