reshape vector to matrix

3 vues (au cours des 30 derniers jours)
Anurag Gupta
Anurag Gupta le 25 Oct 2020
Commenté : Anurag Gupta le 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.

Réponse acceptée

Stephen23
Stephen23 le 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
  1 commentaire
Anurag Gupta
Anurag Gupta le 27 Oct 2020
Thanks a lot Stephen.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by