Seeking Help: Deleting Redundancy in a Structure Array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wei Wen
el 24 de En. de 2024
Comentada: Bruno Luong
el 24 de En. de 2024
Hello,
I hope this message finds you well. I have a question regarding comparing elements in a structure array in MATLAB. Below is the code snippet I am working with, and I'm looking for guidance on identifying and removing redundancy
clear
clc
a(1).pos=[1,7,1];
a(2).pos=[1,7,1];
a(3).pos=[6,5,5];
a(4).pos=[1,4,3];
a(5).pos=[2,2,2];
In this example, I want to find and delete redundant elements within the structure array. Specifically, if I know that a(1).pos and a(2).pos have the same elements, I want to retain only one instance.
I am seeking assistance on how to code this efficiently. Any insights or code snippets would be greatly appreciated. Thank you in advance for your help!
2 comentarios
Bruno Luong
el 24 de En. de 2024
Can we assume
a(i).pos
are 1 x 3 numercal array or they can be something else more generic?
Respuesta aceptada
Bruno Luong
el 24 de En. de 2024
a(1).pos=[1,7,1];
a(2).pos=[1,7,1];
a(3).pos=[6,5,5];
a(4).pos=[1,4,3];
a(5).pos=[2,2,2];
P = cat(1, a.pos);
[~, I] = unique(P, 'rows');
a = a(sort(I));
a.pos
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!