creating sequences of unique integers drawn from an interval, which overlap with other sequences to a ceratin degree
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A K
el 3 de Jun. de 2014
Comentada: Geoff Hayes
el 4 de Jun. de 2014
Hello Gurus
Need your help with creating a list of integer sequences that are unique within the sequence but have certain number of common integers with other sequenes in the list.
Now we can create a list of sequences by using the combnk function in matalab which gives all the combinations of integers in a particular interval, So combnk(1:6,4) gives
3 4 5 6
2 4 5 6
2 3 5 6
2 3 4 6
2 3 4 5
1 4 5 6
1 3 5 6
1 3 4 6
1 3 4 5
1 2 5 6
1 2 4 6
1 2 4 5
1 2 3 6
1 2 3 5
1 2 3 4
but I want only those sequences that differ from all other sequnces by a max of two integers for example so I want only
3 4 5 6
1 2 5 6
1 2 3 4
all other sequnces are ignored.Can you pls give me formula to calculate the number of such sequnces in a list, and also if there is a function that does this Thanks in Advance
0 comentarios
Respuesta aceptada
Geoff Hayes
el 3 de Jun. de 2014
Editada: Geoff Hayes
el 4 de Jun. de 2014
You could use the intersect function (type help intersect in the Command Window for details) to determine how many elements are common in any two rows of the matrix A, and if that number is greater than two, then you know to exclude that second row. If you were to start with the first row, you could then compare all others to it and remove those that have more than two elements in common:
% suppose A is your matrix from above
m = size(A,1);
rowsToRemove = []; % lis
for i=2:m % start with second row and iterate over all remaining rows of A
if length(intersect(A(1,:),A(i,:)))>2
% record this i as a row to remove
rowsToRemove = [rowsToRemove ; i];
end
end
% remove all rows from A that have more than 2 elements in common with row 1
A(rowsToRemove,:) = [];
A is now (perhaps) reduced in size, so repeat the above starting at the second row. Keep iterating in this manner until there you have reached the last row of the (reduced) A. And you're done.
2 comentarios
Geoff Hayes
el 4 de Jun. de 2014
Coming up with an analytical formula would be interesting. Perhaps summing up all possibilities of there being no two elements in common, exactly one element in common, and exactly two elements in common. That may be doable.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!