How to check if a cell of arrays only contains disjoint elements?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!