所以,如果我理解正確,你想提取元素1-91,366-457,731-822,等等?我不知道,有一種方法與基本矩陣索引要做到這一點,但你可以做到以下幾點:
days = 1:365; %Create array ranging from 1 - 365
difference = length(data) - 365; %how much bigger is time series data?
padded = padarray(days, [0, difference], 'circular'); %extend to fit time series
extracted = data(padded <= 91); %get every element in the range 1-91
基本上就是我做的是創建一個數組,其大小爲您的時間序列相同一遍又一遍地重複1-365的數據。然後我上data
執行邏輯索引,使得填充的陣列是小於或等於91
作爲更親切例子,考慮:
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
days = 1:5;
difference = length(x) - 5;
padded = padarray(days, [0, difference], 'circular');
extracted = x(padded <= 2);
padded
然後等於[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
和extracted
會[1, 2, 6, 7]