필터 지우기
필터 지우기

how to merge tables without any common keywords?

조회 수: 12 (최근 30일)
Taoli Li
Taoli Li 2016년 1월 18일
편집: Walter Roberson 대략 24시간 전
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 대략 24시간 전
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