From: Wayne King on
"santhosh " <santhosh.ayalur(a)gmail.com> wrote in message <hrjm91$5mg$1(a)fred.mathworks.com>...
> Hi am a beginner to Matlab and have a problem with reshaping a matrix.
>
> I have a matrix which is 1024*4, which is actually a compound of two data sets that are 512*4*2.
>
> that is in short if my matrix is
> 1 2
> 3 4
> 5 6
> 7 8
> 9 10
> 11 12
>
> I want to reshape it as
> 1 2 7 8
> 3 4 9 10
> 5 6 11 12
>
> How do i do this. I bet its a simple thing for you...
> Thanks for your help

Hi, the simple thing is to use reshape:

A =[1 2
3 4
5 6
7 8
9 10
11 12];
B = reshape(A,size(A,1)/2,size(A,2)*2);

But you will see that the result is not what you have indicated above. The elements in B are taken columnwise from A so that B will be:
1 7 2 8
3 9 4 10
5 11 6 12

Are you sure the structure you have indicated for the reshaped matrix is the one you want? Do you really want the 2nd and 3rd columns in the order you have indicated? Or do you want them as reshape() returns?

Wayne
 | 
Pages: 1
Prev: reshaping matrix
Next: reshaping matrix