In Matlab
1) If I have a vector, say [1 2 3] then I'm looking to create a matrix that contains every permutation of the vector, with another column appended containing, for each permutation, the first element of the original vector. I'd then like this matrix to be appended (by row) to another where the appended column is the second element. Then following this the same thing with the 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 is a long form way of writing it but I'm certain that someone here will be able to write it in a very 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) Is there a way of doing a 'mostly random' ordering where, say you had a list such as:
60 67 64 70
74 71 67 74
74 79 71 82
77 74 71 77
71 79 74 82
65 62 71 65
64 72 67 75
74 71 77 74
69 72 65 75
77 69 74 72
74 71 65 74
69 72 76 75
69 62 65 65
76 67 71 70
69 76 72 79
65 74 69 77
74 65 69 68
67 71 74 74
69 64 60 67
65 72 69 75
74 71 79 74
71 67 62 70
65 71 74 74
62 69 65 72
60 69 65 72
60 69 64 72
71 64 67 67
72 69 76 72
69 60 65 63
you could order this so that the row order is random but that all of the numbers in the first column are mostly close to each other by a defined parameter (for example 62 might be followed by 67 or 58 but wouldn't be followed by say 80)? (To make things even more complicated might there be a way of specifying that this take place most but not all of the time?)
3) What's a concise way of creating a column vector that goes
0
0
0
0
1
1
1
1
2
2
2
2
3
3
3
3
etc, up until a specified length (or, failing that, up until a specified number)?
Aucun commentaire:
Enregistrer un commentaire