Rolling-window matrix with different intervals between columns.

1 次查看(过去 30 天)
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

回答(2 个)

Wieszner Vilmos
Wieszner Vilmos 2019-6-11
Hi,
I think this is what you are looking for:

Jan
Jan 2019-6-11
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)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by