Finding specific values on one table based on values in another table

I have two (3x100) tables. The first table (T1) consists of ID codes (1-10) and the second consists of scores related to that id code. I am interested in extracting values from T2 at specific values of T1, say 4, for example. I have tried join() and vertcat() but all those do is combine the two tables which makes it tedious for me to look at the values one by one. Is there a way for me to find all the values in T2 connected to a specific value in T1?
Above is after new_table=[t1; t2]. Rows 1-3 are from T1 and 4-6 are from T2 originally. In the above examle, I am interested in extracting all the values in T2 when T1=6.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 9 日

0 投票

Following code shows an example of what you are trying to do
% geenrating random tables
table1 = array2table(randi(5, 5, 10));
table2 = array2table(rand(5, 10));
b_ = table2array(table2);
result_1 = b_(table1.Variables==1);
result_2 = b_(table1.Variables==2);
It extracts all values from table2, at locations where elements of table1 have specific values.

1 件のコメント

Shah
Shah 2020 年 3 月 10 日
Thanks, this was exactly what I needed.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2020 年 3 月 9 日

コメント済み:

2020 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by