Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Copy a set of coloumn from one matrix to another.

Subject: Copy a set of coloumn from one matrix to another.

From: Bal kishore Pandey

Date: 10 Nov, 2011 18:29:11

Message: 1 of 5

Dear friends,
Let me explain my situation.
I have a two matrix say A and B of same size (i.e) 5000x800.
matrix A has some values and matrix B is a zero matrix.
Now what i have to do is, i have to set a window of size say 10(10 elemnts of a row), and a window of say size 10 again(coloumn). Now i have to create a program which could copy the first ten elements of coloum 1 according to the size of window coloumn to the matrix B.
once copied, it should copy the next 10 elements from the second coloumn(but it should not copy the first 10 elements of the 2nd coloumn, instead it should copy the next 10 elemtents). It should keep on doing this untill the size of window row is reached. Once the row window size is reached it should repeat the copy process of the coloumn.

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

Subject: Copy a set of coloumn from one matrix to another.

From: Parag Chandakkar

Date: 11 Nov, 2011 02:56:53

Message: 2 of 5

On Nov 10, 11:29 am, "Bal kishore Pandey"
<balkishore.pan...@gmail.com> wrote:
> Dear friends,
> Let me explain my situation.
> I have a two matrix say A and B of same size (i.e) 5000x800.
> matrix A has some values and matrix B is a zero matrix.
> Now what i have to do is, i have to set a window of size say 10(10 elemnts of a row), and a window of say size 10 again(coloumn). Now i have to create a program which could copy the first ten elements of coloum 1 according to the size of window coloumn to the matrix B.
> once copied, it should copy the next 10 elements from the second coloumn(but it should not copy the first 10 elements of the 2nd coloumn, instead it should copy the next 10 elemtents). It should keep on doing this untill the size of window row is reached. Once the row window size is reached it should repeat the copy process of the coloumn.
>
> 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

Question is not very clear.
- Parag S Chandakkar

Subject: Copy a set of coloumn from one matrix to another.

From: Roger Stafford

Date: 11 Nov, 2011 03:36:28

Message: 3 of 5

"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
- - - - - - - - -
  As nearly as I could decipher your request, the following might do the job. Let r be the "row_window_size" and c the "column_window_size". Then do this:

 p = size(A,1);
 ix = ceil((1:p*c)/c)+p*mod(0:p*c-1,r*c);
 B(ix) = A(ix);

  It seems to me you are confusing rows with columns in some of your description, so I am far from certain that this is what you really want. Moreover it isn't clear that the copy process should end when reaching the bottom row of A. Perhaps you meant for it to recommence back up at the first row again and r*c elements over to the right? The above code does not do that.

Roger Stafford

Subject: Copy a set of coloumn from one matrix to another.

From: Roger Stafford

Date: 11 Nov, 2011 17:45:28

Message: 4 of 5

"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

Subject: Copy a set of coloumn from one matrix to another.

From: Bal kishore Pandey

Date: 11 Nov, 2011 21:28:11

Message: 5 of 5

"Roger Stafford" wrote in message <j9jmvo$f3s$1@newscl01ah.mathworks.com>...
> "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


Thank you very much mate!! this helped a lot!! thank you very much!! don't have words to describe it!!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us