How do I delete a row in a matrix where the first value isn't in a corresponding matrix?

2 ビュー (過去 30 日間)
I have 2 tables like this:
table files:
| id | ....
------------
| 1 | ....
| 2 | ....
| 7 | ....
| 9 | ....
table blob:
| fileid | ....
------------
| 1 | ....
| 2 | ....
| 3 | ....
| 4 | ....
| 5 | ....
| 7 | ....
| 9 | ....
The tables fileid and id columns can be used to join the tables together.
How do I delete columns 3 4 5. Keep in mind this is only a simple example, I have a data set that contains thousands of rows

採用された回答

Thorsten
Thorsten 2016 年 7 月 20 日
編集済み: Thorsten 2016 年 7 月 20 日
Create a logical index that has a 1 at each position where fileid has no match in id:
idx = ~ismember(fileid, id);
Delete the corresponding rows in your matrix A:
A(idx,:) = [];
  2 件のコメント
Humblespud
Humblespud 2016 年 7 月 20 日
Could you elaborate a bit more please? I am relatively new to Matlab.
Thorsten
Thorsten 2016 年 7 月 20 日
Sorry. I've updated my answer.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 7 月 20 日
Try intersect() to find numbers that are common to both.
commonNumbers = intersect(fileid{:,1}, id{:,1});
Then use ismember() to find out where the numbers in commonNumbers occur in each table, say these are called rows1 and rows2.
Then use innerjoin():
newTable = innerjoin(fileid({rows1,1}, id{rows2,1});
Or something like that - that's untested, just off the top of my head. Or maybe you want outerjoin()???

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by