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

3 views (last 30 days)
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 Comments
MiauMiau
MiauMiau on 17 May 2014
sure:
>> y{2}
ans =
107.2970
197.1180
197.2550
301.1360
-26.8370
212.5520
165.9510
141.8780
167.1560
147.4240

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 17 May 2014
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.

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!