Compare two tables's rownames (A and B), if the rownames of B are in A then add a column in A with the columns in B

1 回表示 (過去 30 日間)
Hi all,
I have two tables. Table A (995*7 table) and Table B (16*1 table). I want to compare the rownames of both. I want to add a column in A that will show the value associated to the rowname that matches B.
e.g.
A table:
RowNames Var1 Var2 Var3
a . . .
b . . .
c . . .
d . . .
e . . .
B table:
RowNames Var1
b tower
z bottom
y top
result table A:
RowNames Var1 Var2 Var3 VarNEW
a . . . (empty)
b . . . Tower
c . . . (empty)
d . . . (empty)
e . . . (empty)
Hope you can help me
Thank you

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 10 月 11 日
編集済み: Cris LaPierre 2021 年 10 月 11 日
I would first try using the Join Tables live task. This will interactively let you align two tables using key variables. Once you have the table you want, you can generate the corresponding code.
The live task represents the different ways of joinging two tables visually using Venn diagrams. Here's a screenshot of what the app looks like.
  2 件のコメント
Usune Elizondo
Usune Elizondo 2021 年 10 月 11 日
Thank you for the answer, but I just have shown a simple example. I have a lot of tables and I am working with loops to format and do calculations. Al the tables are inside a structure, is it possible to get the code for one table and then modify it so I can use it for all? Or do I need to load one by one each of them?
Cris LaPierre
Cris LaPierre 2021 年 10 月 11 日
We can only answer the question that is asked.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by