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

1 visualización (últimos 30 días)
MiauMiau
MiauMiau el 17 de Mayo de 2014
Respondida: Star Strider el 17 de Mayo de 2014
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 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 17 de Mayo de 2014
Can you explain how your cell array looks like? give an example
MiauMiau
MiauMiau el 17 de Mayo de 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

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 17 de Mayo de 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.

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by