Splitting k - combinations into 2 in a specific manner in Matlab -


consider set,

 s = {1,2,3,4,5,6,7} 

i trying come function takes s input , gives me possible arrays:

 [ 1 ~ 2 ; 1 ~ 3 ; 1 ~ 4 ; 1 ~ 5 ; . . . ; 6 ~ 7 ]  [ 1 2 ~ 3 ; 1 2 ~ 4 ; ...; 2 3 ~ 1 ; 2 3 ~ 4....; 5 6 ~ 7]  .  .  .  [ 2 3 4 5 6 7 ~ 1 ; 1 3 4 5 6 7 ~ 2 ; ... ; 1 2 3 4 5 6 ~ 7 ] 

here notice '~' sort of delimiter placed in between elements of k - combination such set appearing before delimiter unique in each array.

for example, want both 7-combinations

 [ 2 3 4 5 6 7 ~ 1 ] , [ 1 2 3 4 5 6 ~ 7 ]. 

but want 1 of

 [ 1 2 3 4 5 6 ~ 7 ] , [ 1 3 4 5 6 2 ~ 7 ]. 

my code :

clear k = 1:7     set = nchoosek(1:7,k);          = 1:length(set)             = setdiff(1:7,set(i,:));             p = nchoosek( , 2 ); % trialing a~b b has 2elements             l = length( p );             s = repmat( set ( i,: ) , l,1);              j = 1:l                  s1(j,:) = setdiff( s(j,:) , p(j,:) );                 w(j,:) = [ s1(j,:) , 0 , p(j,:) ];              end               w1(i,k) = {w};          end  end 

this produces error @ k=2. ideas make work , efficiently.

i think can outline how achieve this.

  • to subset (for a) use setdiff

    s = 1:7 b = 4 tmp = setdiff(s,b)

  • for permutation use randperm

    t2 = randperm(length(tmp)) = tmp(t2)

  • for specific subsets pick first n entries of a

put whole thing in loops create set describe.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -