Rolling-window matrix with different intervals between columns.

4 Ansichten (letzte 30 Tage)
farshid balaneji
farshid balaneji am 13 Jan. 2018
Beantwortet: Jan am 11 Jun. 2019
Hi,
I have a vector of data for 21 years with daily data and want to create a rolling window of 365 days such as the next period stars one month (30 days) after the previous one, for example:
vec = [1 2 3 4 5 6 7 8 9 10 11 12 13]
for a given variable n_interval = 3, I want to get a matrix output like:
mat = [[1 2 3 4 5],
[4 5 6 7 8],
[7 8 9 10 11],
[10 11 12 13]]
I looked at this question but couldn't apply it to my problem.
Any help would be appreciated

Antworten (2)

Wieszner Vilmos
Wieszner Vilmos am 11 Jun. 2019
Hi,
I think this is what you are looking for:

Jan
Jan am 11 Jun. 2019
vec = [1 2 3 4 5 6 7 8 9 10 11 12 13];
n = numel(vec);
step = 3;
width = 4;
col1 = 1:step:n - width + 1;
row1 = 0:width - 1;
index = col1.' + row1;
result = vec(index)

Community Treasure Hunt

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

Start Hunting!

Translated by