Deduplicate Rows from Struct

5 visualizaciones (últimos 30 días)
Rounak Saha Niloy
Rounak Saha Niloy el 9 de Ag. de 2022
Comentada: Rounak Saha Niloy el 9 de Ag. de 2022
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 comentarios
Matt J
Matt J el 9 de Ag. de 2022
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 el 9 de Ag. de 2022
Fourth row is to be removed.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 9 de Ag. de 2022
Editada: Matt J el 9 de Ag. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by