MATLAB Answers

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

6 views (last 30 days)
WeiShan Ng
WeiShan Ng on 26 Jun 2020
Answered: Akira Agata on 26 Jun 2020
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?

  0 Comments

Sign in to comment.

Answers (1)

Akira Agata
Akira Agata on 26 Jun 2020
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)]';

  0 Comments

Sign in to comment.