Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Copy a set of coloumn from one matrix to another.
Date: Fri, 11 Nov 2011 17:45:28 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <j9jmvo$f3s$1@newscl01ah.mathworks.com>
References: <j9h55n$qht$1@newscl01ah.mathworks.com> <j9i57s$9q2$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1321033528 15484 172.30.248.47 (11 Nov 2011 17:45:28 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 11 Nov 2011 17:45:28 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:749143

"Roger Stafford" wrote in message <j9i57s$9q2$1@newscl01ah.mathworks.com>...
> "Bal kishore Pandey" <balkishore.pandey@gmail.com> wrote in message <j9h55n$qht$1@newscl01ah.mathworks.com>...
> > ..........
> > For eg, A= [1 2 3 4 5 6 7 8 9
> >                  9 8 7 6 5 4 3 2 1
> >                  3 4 5 6 4 5 6 8 9 
> >                  6 7 8 9 3 4 5 6 7
> >                  3 4 6 7 8 9 0 1 2 ]  
> > 
> > I have this matrix and my coloumn_window_size is 2 and my row_window_size is 3 then the code should copy 1 2(coloumn 1 in A) to B matrix exactly in the same position it was in A. Then it should copy 7 6(coloumn 2) , and then 4 5(coloumn 3) and it should start again from the 4th coloumn copying 6 7 , 6 7
> - - - - - - - - -
>  p = size(A,1);
>  ix = ceil((1:p*c)/c)+p*mod(0:p*c-1,r*c);
>  B(ix) = A(ix);
- - - - - - - - - - -
  The code I gave earlier only repeats your r by r*c window pattern vertically.  The following will repeat it both vertically and horizontally as far as the size of A permits.

  Again let r be the "row_window_size" and c the "column_window_size".  Then do:

 [p,q] = size(A);
 pe = r*ceil(p/r);
 qe = r*c*ceil(q/(r*c));
 s = 0:(pe*qe)/r-1;
 ix = mod(floor(s/c),pe);
 jx = mod(s,r*c)+r*c*floor(s/(pe*c));
 b = (ix<p)&(jx<q);
 kx = ix(b)+1+p*jx(b);
 B(kx) = A(kx);

Roger Stafford