MATLAB: Reshape vector to matrix

vector to matrix

I want to convert
d = [1 2 3 4 5]
to d = [1 2
2 3
3 4
4 5]
is there anyway I can do it.

Best Answer

A general solution for an arbitrary number of rows and columns:
>> d = [1,2,3,4,5];
>> r = 4;
>> m = hankel(d(1:4),d(r:end))
m =
1 2
2 3
3 4
4 5