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]]
Any help would be appreciated
0 个评论
回答(2 个)
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)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!