reshape vector to matrix

3 Ansichten (letzte 30 Tage)
Anurag Gupta
Anurag Gupta am 25 Okt. 2020
Kommentiert: Anurag Gupta am 27 Okt. 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.

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by