필터 지우기
필터 지우기

Deduplicate Rows from Struct

조회 수: 8 (최근 30일)
Rounak Saha Niloy
Rounak Saha Niloy 2022년 8월 9일
댓글: Rounak Saha Niloy 2022년 8월 9일
I have the following struct-
Database.x = [1 0 1
2 0 2
3 0 1
1 0 1];
Database.f = [10 20
20 30
30 40
10 15];
In Database.x, there are duplicate rows (1st and 4th one). I want to deduplicate them and based on that, I want to remove the corresponding row from Databse.f
How do I do this?
  댓글 수: 2
Matt J
Matt J 2022년 8월 9일
I want to remove the corresponding row from Databse.f
In referene to your example, how would you decide whether the first or fourth row of f should be removed?
Rounak Saha Niloy
Rounak Saha Niloy 2022년 8월 9일
Fourth row is to be removed.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2022년 8월 9일
편집: Matt J 2022년 8월 9일
How about this?
Database.x = [1 0 1
2 0 2
3 0 1
1 0 1];
Database.f = [10 20
20 30
30 40
10 15];
[Database.x,I]=unique(Database.x,'rows');
Database.f=Database.f(I,:);
Database.x
ans = 3×3
1 0 1 2 0 2 3 0 1
Database.f
ans = 3×2
10 20 20 30 30 40

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by