Very easy: use reshape
:
X = 1:1000;
k = 100;
Y = reshape(X,k,[]).';
Or, if you have the Communications Toolbox, you can use vec2mat
:
Y = vec2mat(X,k);
Question
In Matlab, say you have a large vector X
X = [1 2 3 4 5 6 ... 1000]
How would you select an array of K element subsets with incrementing indices? (No for loops please).
k = 100; % 100 element subsets
Y = foo(X,k);
>> Y =
1 2 3 ... 100
101 102 103 ... 200
201 202 203 ... 300
. . . ... .
. . . ... .
. . . ... .
901 902 903 ... 1000
Thanks
-----Update--------
Thanks for the quick reply. I hate it when ask stupid questions.
Now, I have a more challenging one (what I really wanted to know). Given:
X = [1 2 3 4 5 6 ... 1000];
k = 900;
How do you produce?
Y = foo(X,k);
>> Y = 1 2 3 ... 900
2 3 4 ... 901
3 4 5 ... 902
. . . ... .
. . . ... .
. . . ... .
100 101 102... 1000
Thanks again