On 12/31/2011 1:05 AM, Roger Stafford wrote:
> "Kfupm engsub" wrote in message<jdifh4$s4r$1@newscl01ah.mathworks.com>...
>> I have a very large matrix. A simple example is:
>> Suppose I have this matrix:
>>
>> M= [50 55 52 51
>> 20 21 24 23
>> 1 1 2 2
>> 1 2 1 2
>> 89 88 80 82];
>>
>> I want to construct a new matrix that gathers every two columns
>> by rowise following in one vector. So, the desired matrix is:
>>
>> A= [50 52
>> 55 51
>> 20 24
>> 21 23
>> 1 2
>> 1 2
>> 1 1
>> 2 2
>> 89 80
>> 88 82] ;
>          
> Try this horror:
>
> [p,q] = size(M); % The number of columns, q, must be even
> n = 0:p*q1;
> A = reshape(M((2*mod(n,2*p)(2*p1)*(1).^n+2*p+3)/4+2*p*floor(n/2/p)),2*p,q/2);
>
> Roger Stafford
wow, I am not going to figure how you came up with this one Roger ;)
How about one with few more lines? This is my attempt: It assumes
also even rows/columns.

clear all;
M= [50 55 52 51
20 21 24 23
1 1 2 2
1 2 1 2
89 88 80 82];
[p,q]=size(M);
np=p*q/2;
B=zeros(np,2); %make storage for result
%make the 2 sub matrices
m1=reshape(M(:,1:2:q),[np/2,2]);
m2=reshape(M(:,2:2:q),[np/2,2]);
%stuff them into the result matrix
B(1:2:np,:)=m1;
B(2:2:np,:)=m2;

B =
50 52
55 51
20 24
21 23
1 2
1 2
1 1
2 2
89 80
88 82
Nasser
