Azzera filtri
Azzera filtri

how to merge tables without any common keywords?

12 visualizzazioni (ultimi 30 giorni)
Taoli Li
Taoli Li il 18 Gen 2016
Modificato: Walter Roberson circa 24 ore fa
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 Commento
Walter Roberson
Walter Roberson il 26 Lug 2024 alle 5:14
Modificato: Walter Roberson circa 24 ore fa
I have to wonder whether table here refers to numeric matrices, or to table objects ?

Accedi per commentare.

Risposte (1)

BhaTTa
BhaTTa il 26 Lug 2024 alle 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

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by