1
votes

I have a matrix X of size [N, D1] , and I want to obtain a new matrix X2 [N2, D2], where the output X2 should look like this :

f(X,D2) = X2 =

[ part 1 of X(1,:)   === X(1, 1 : D2)
  part 2 of X(1,:)   === X(1, D2+1 : 2*D2) , etc
  ...
  part K of X(1,:)
  part 1 of X(2,:)
  ...
  ...
  part K of X(N,:) ]

so D2 will be supplied such that mod(D1,D2)=0; Therefore, N2 = N * D1/D2.

I couldn't make reshape work for this purpose. Maybe I can do this with a for loop but I wonder if there is a vectorized / efficient way for this.

Thanks for any help!

Example input

X = [1, 2, 3, 4,  5,  6
     7, 8, 9, 10, 11, 12]

Which has 6 columns, so I want to divide it into columns of 3:

f(X,3) = [1,2,3
          4,5,6
          7,8,9
            ...]
1
I suggest adding a simple numerical example (input and desired output) to your question to make sure that everybody understand exactly what you are asking.Hoki
@Hoki good suggestion, doing it right now :)jeff

1 Answers

2
votes

I found the solution. It was as simple as transposing, reshaping and then transposing again.

So for my example, the solution would be:

X2 = reshape(X',3,[])';

Sorry for such a simple question, but I will still keep it in case it helps others too.