create a matrix using a vector such that each row is one offset of the previous row

4 ビュー (過去 30 日間)
WeiShan Ng
WeiShan Ng 2020 年 6 月 26 日
回答済み: Akira Agata 2020 年 6 月 26 日
Let say I have a vector v = [v1, v2, v3, v4, ..., vn], I would like to create a matrix using the vector such that each row is one offset of the previous row, i.e.
matrix = [v1 v2 v3;
v2 v3 v4;
v3 v4 v5;
v(n-2) v(n-1) v(n)]
How can I achieve this?

回答 (1 件)

Akira Agata
Akira Agata 2020 年 6 月 26 日
If the output matrix is always N-by-3, the following straight-forward way might be enough:
matrix = [v(1:end-2);v(2:end-1);v(3:end)]';

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by