matlab - Appending specified vector elements to all permutations of the vector, 'mostly random' row ordering for nearby integers etc -
in matlab
1) if have vector, [1 2 3] i'm looking create matrix contains every permutation of vector, column appended containing, each permutation, first element of original vector. i'd matrix appended (by row) appended column second element. following same thing third. i.e.:
3 2 1 1 3 1 2 1 2 3 1 1 2 1 3 1 1 2 3 1 1 3 2 1 3 2 1 2 3 1 2 2 2 3 1 2 2 1 3 2 1 2 3 2 1 3 2 2 3 2 1 3 3 1 2 3 2 3 1 3 2 1 3 3 1 2 3 3 1 3 2 3
this long form way of writing i'm here able write in concise way instead:
a = [1 2 3]; b = perms(a); c = [a(1); a(1); a(1); a(1); a(1); a(1)] ; d = [a(2); a(2); a(2); a(2); a(2); a(2)] ; e = [a(3); a(3); a(3); a(3); a(3); a(3)] ; f = [ c; d; e ] g = [ b; b ; b] h = [g f]
2) there way of doing 'mostly random' ordering where, had list such as:
64 69 72 72 64 72 69 75 76 67 72 70 62 69 65 72 71 74 65 77 74 69 65 72 67 71 74 74 67 76 72 79 76 79 71 82 60 64 69 67 64 67 72 70 67 64 60 67 72 65 69 68 74 71 65 74 65 69 62 72 71 74 67 77 71 62 65 65 67 72 64 75 77 74 71 77 76 72 67 75 77 69 74 72 74 67 71 70 79 71 74 74 76 71 79 74 69 62 65 65 65 62 71 65 69 65 74 68 69 64 60 67 71 79 74 82 71 74 77 77 69 74 77 77 72 69 77 72 77 72 69 75 74 65 71 68 71 62 67 65 71 77 74 80 74 77 71 80 77 71 74 74 69 65 72 68 65 71 74 74 67 71 76 74 64 67 60 70 65 72 69 75 71 74 79 77 72 76 69 79 67 62 71 65 72 69 65 72 69 72 76 75 79 74 71 77 72 67 64 70 71 67 76 70 67 72 76 75 71 65 74 68 65 69 60 72 69 72 77 75 64 69 60 72 76 69 72 72 69 76 72 79 64 72 67 75 72 77 69 80 67 76 71 79 69 60 65 63 67 60 64 63 71 64 67 67 69 60 64 63 71 67 62 70 60 64 67 67 74 69 77 72 65 74 71 77 62 71 65 74 67 71 64 74 65 74 69 77 76 67 71 70 62 67 71 70 74 71 79 74 77 74 69 77 67 64 71 67 62 65 71 68 65 60 69 63 62 65 69 68 60 69 65 72 71 65 62 68 65 69 74 72 67 74 71 77 71 79 76 82 69 74 65 77 69 77 72 80 67 71 62 74 72 64 67 67 74 77 69 80 76 72 69 75 69 72 65 75 71 76 79 79 64 60 67 63 64 60 69 63 74 65 69 68 79 76 71 79 64 67 71 70 72 67 76 70 72 76 67 79 69 65 60 68 60 67 64 70 69 64 72 67 69 65 62 68 65 62 69 65 74 71 67 74 65 69 72 72 72 69 64 72 60 69 64 72 76 71 67 74 64 71 67 74 60 65 69 68 74 79 71 82 65 71 62 74 67 64 72 67 71 67 74 70 79 71 76 74 62 71 67 74 74 71 77 74 71 67 64 70 72 64 69 67 71 76 67 79 69 77 74 80 77 69 72 72 69 72 64 75 72 69 76 72
you order row order random of numbers in first column close each other defined parameter (for example 62 might followed 67 or 58 wouldn't followed 80)? (to make things more complicated might there way of specifying take place not of time?)
3) what's concise way of creating column vector goes
0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3
etc, until specified length (or, failing that, until specified number)?
for 1) can use code:
%sprows utility function, splits matrix cell sprows=@(x)(mat2cell(x,ones(size(x,1),1))) %get combinations of perms(a) , cell2mat(allcomb(sprows(perms(a)),sprows(a(:))))
it uses allcomb
matlab file exchange, available here
3):
x=repmat(0:3,4,1); x=x(:);
Comments
Post a Comment