Extract rows with a range of values
조회 수: 2 (최근 30일)
이전 댓글 표시
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
2019년 6월 26일
Are these large tables? There are some direct methods that can vectorize but which take a fair bit of memory.
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!