How to make a structure unique?

17 views (last 30 days)
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.
  4 Comments
Md. Asadujjaman
Md. Asadujjaman on 25 Jun 2020
sorry, X values are a row vector

Sign in to comment.

Accepted Answer

Rasul Khan
Rasul Khan on 25 Jun 2020
Edited: Rasul Khan on 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 Comments
Md. Asadujjaman
Md. Asadujjaman on 25 Jun 2020
Thank you. It's working.
I got the result.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!

Translated by