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 件のコメント

Walter Roberson
Walter Roberson 2020 年 6 月 25 日
Will there ever be a case where the x values are not row vectors? Will there ever be a case when the row vectors are not the same length? For example will any of the entries ever be empty?
Md. Asadujjaman
Md. Asadujjaman 2020 年 6 月 25 日
X values are not a row vector.
Row vectors are the same length.
Here, the 'info' and 'fit' entities are empty. After making the structure (pop) unique, I will do some analysis and therefore the 'info' and 'fit' entities would not be empty.
It would be also helpful for if anyone can make the following structure (pop) unique.
emp.x=[];
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];
Result wouldbe as follows:
Walter Roberson
Walter Roberson 2020 年 6 月 25 日
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.)
Md. Asadujjaman
Md. Asadujjaman 2020 年 6 月 25 日
sorry, X values are a row vector

サインインしてコメントする。

 採用された回答

Rasul Khan
Rasul Khan 2020 年 6 月 25 日
編集済み: Rasul Khan 2020 年 6 月 25 日

1 投票

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 件のコメント

Walter Roberson
Walter Roberson 2020 年 6 月 25 日
m = vertcat(pop.x);
[~ , ia , ~] = unique(m , 'rows');
pop = pop(ia);
Md. Asadujjaman
Md. Asadujjaman 2020 年 6 月 25 日
Thank you. It's working.
I got the result.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by