How to check if a cell of arrays only contains disjoint elements?

2 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2014 年 5 月 17 日
回答済み: Star Strider 2014 年 5 月 17 日
Hi
I have so far the following code:
data = xlsread('filename');
% 1000 samples without replacement
% each element of y contains 10 values without repetition
y = cell(10,1000);
for i = 1:1000
y{i} = datasample(x,10,'Replace',false);
end
Now I dont want to have the same vector twice in the cell y, and by twice I also mean vectors like [ 1 2 3 4 5 6 7 8 9 10] and [1 2 3 4 5 6 7 8 10 9], i.e the ordering of the elements does not matter, but if 2 vectors contain the same elements I want one to be deleted. How do I do that? Is there alternatively a way to sample some of combinations without replacement from data? Data contains 171, and all of the combinations without repetition would probably would some millions whereas I only need around 1000 combinations.. Thanks
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 17 日
Can you explain how your cell array looks like? give an example
MiauMiau
MiauMiau 2014 年 5 月 17 日
sure:
>> y{2}
ans =
107.2970
197.1180
197.2550
301.1360
-26.8370
212.5520
165.9510
141.8780
167.1560
147.4240

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

回答 (1 件)

Star Strider
Star Strider 2014 年 5 月 17 日
Use unique:
y2 = [107.2970
197.1180
197.2550
301.1360
-26.8370
212.5520
165.9510
141.8780
167.1560
147.4240
147.4240];
[C,iy2,ic] = unique(y2)
If the length of C = the length of y2, all the elements of y2 are unique, i.e. disjoint.
If the length of y2 is greater than the length of C, the difference is the number of repeated (non-unique, non-disjoint) elements in y2.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by