reshape vector to matrix

6 views (last 30 days)
Anurag Gupta
Anurag Gupta on 25 Oct 2020
Commented: Anurag Gupta on 27 Oct 2020
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.

Accepted Answer

Stephen23
Stephen23 on 25 Oct 2020
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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!