Rolling-window matrix with different intervals between columns.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Descriptive Statistics and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!