How to make a structure unique?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Md. Asadujjaman
am 25 Jun. 2020
Kommentiert: Md. Asadujjaman
am 25 Jun. 2020
emp.x=[];
emp.info=[];
emp.fit=[];
pop=repmat(emp,1,1);
pop(1).x=[1 2 3 4];
pop(2).x=[3 2 1 4];
pop(3).x=[1 2 3 4];
pop(4).x=[2 1 3 4];
How to make the above structure (pop) unique?
The result would be like the following figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321673/image.jpeg)
4 Kommentare
Walter Roberson
am 25 Jun. 2020
X values are not a row vector.
Row vectors are the same length.
Which row vectors are the same length as each other if they are not the X values? (We know they are not the X values because you said that the X values are not row vectors.)
Akzeptierte Antwort
Rasul Khan
am 25 Jun. 2020
Bearbeitet: Rasul Khan
am 25 Jun. 2020
You can achieve it using this script.
m = [];
for i = 1 : numel(pop)
m = [m ; pop(i).x];
end
[~ , ia , ~] = unique(m , 'rows');
pop = pop(ia);
2 Kommentare
Walter Roberson
am 25 Jun. 2020
m = vertcat(pop.x);
[~ , ia , ~] = unique(m , 'rows');
pop = pop(ia);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!