フィルターのクリア

Extract rows with a range of values

2 ビュー (過去 30 日間)
Syeda Amberin
Syeda Amberin 2019 年 6 月 26 日
回答済み: Walter Roberson 2019 年 6 月 26 日
I have two tables. The first table (tab1) has column with ids. We call it ID. The second table (tab2) also has ids which is called ID as well. I am trying to extract all the rows in tab2 that has at least one match of ID from tab1. Following is what I have tried:
rev_table=tab2(tab1.ID,:);
Could someone help please?
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 26 日
Are these large tables? There are some direct methods that can vectorize but which take a fair bit of memory.
Syeda Amberin
Syeda Amberin 2019 年 6 月 26 日
No. The tables are not large.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 6 月 26 日
mask = any(any(tab2{:,:} == reshape(tab1.ID, 1, 1, []),3),2);
selected_rows = tab2(mask,:);
Requires R2016b or later in the form written.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by