From: Oleg Komarov on
"Jane " <Jane(a)mytrashmail.com> wrote in message <hn5nv9$n03$1(a)fred.mathworks.com>...
> Hi,
>
> I have a set of numbers 1002 x 20 :
>
> 1 2 3 4 5 6 7 8 9 10 11 12 ...n1002.
> 1 2 3
> 1 2 3
> ...n20
>
> I want do the following.
> ~~~~~~~~~
> A1 = kk(1,1:3:1002)
> A2 = kk(1,2:3:1002)
> A3 = kk(1,3:3:1002)
>
> B1 = A1'
> B2 = A2'
> B3 = A3'
> JJ(1:end,1:3) = [B1,B2,B3];
> ~~~~~~~~~
>
> ~~~~~~~~~
> A4 = kk(2,1:3:1002)
> A5 = kk(2,2:3:1002)
> A6 = kk(2,3:3:1002)
>
> B4 = A4'
> B5 = A5'
> B6 = A6'
> JJ(1:end,4:6) = [B4,B5,B6];
> ~~~~~~~~~
> .
> .
> .
> continue until line 20.
>
> How can I do this faster?

% Small example 4 by 12
kk = ndgrid(1:12,1:4).'
kk =
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12

%{
You want to do:
A1 = kk(1,1:3:1002)
A2 = kk(1,2:3:1002)
A3 = kk(1,3:3:1002)

B1 = A1'
B2 = A2'
B3 = A3'
%}

% Which is equivalent to (look at the pattern):
[kk(1,1:3:end).',kk(1,2:3:end).',kk(1,3:3:end).']
ans =
1 2 3
4 5 6
7 8 9
10 11 12

% So if you actually have a matrix similar to kk from this example then
JJ = repmat(reshape(1:size(kk,2),3,[]).',1,size(kk,1))

% Else you have to be more precise...

Oleg