Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Permutatation of given Matrix with no row repetition Date: Wed, 14 Dec 2011 22:47:07 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 28 Message-ID: <jcb91b$qnn$1@newscl01ah.mathworks.com> References: <jca22g$bdf$1@newscl01ah.mathworks.com> <jcb4is$cb2$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1323902827 27383 172.30.248.48 (14 Dec 2011 22:47:07 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 14 Dec 2011 22:47:07 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 3228552 Xref: news.mathworks.com comp.soft-sys.matlab:752405 "Roger Stafford" wrote in message <jcb4is$cb2$1@newscl01ah.mathworks.com>... > Call the original 4 by 224 matrix A. If I have interpreted your description correctly, the first row of your desired result will be some permutation of the 7 possible numbers occurring in the first row of A, and after that this same permutation must be repeated 31 more times. Otherwise there would be some repetition of elements occurring within a 7-element interval. There are just 7! ways of doing this. Prior to performing this permutation, within each block of 32 in the original A any permutation of the columns in the block is permitted, making 32! possible permutations in each block. Combining these, there are therefore 7!*(32!)^7 possible acceptable permutations of the columns of A. That is a very large number (but not as large as 244!) > > In the following it is assumed that the first row of A is as you indicate with 32 repetitions of the first number, followed by 32 of the second number, then 32 of the third number, etc. > > m = 7; n = 32; > B = A; % Allocate B > for k = 1:m > p = randperm(n); > B(:,(1:n)+n*(k-1)) = A(:,p+n*(k-1)); > end > p = randperm(m).'; > [a,b] = meshgrid(1:n,1:m); > a = a(:); b = b(:); > q = a + n*(p(b)-1); > B = B(:,q); % <-- B is the desired result. > > In the above code the first action is to randomly permute each block of 32 columns, which can be done (32!)^7 ways. In the next part p is a random permutation of 1:7. It is used to rearrange the columns so that the first row consists of 32 repetitions of the permutation determined by p. > > (It will be easier to understand if you try it with smaller numbers for m and n.) > > Roger Stafford Thanks Roger I understood your script, it's brilliant and it seems to work fine :9 Thank you