How to pick data with fix moving window ?

2 ビュー (過去 30 日間)
aa
aa 2021 年 1 月 6 日
コメント済み: Mathieu NOE 2021 年 1 月 6 日
Hi everyone,
May someone help me here...
I have a 366 data points. I am interested to pick 60 data points each time with a shift of 5 data points i.e. 1-60, 5-65, 10-70, 15-75 ..... 305-365.
Thank you.

回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 1 月 6 日
hello
create index vector with delta = 5 :
ind = min(data):5:max(data);
and use it to extract the corresponding data values :
data_out = data(ind);
  3 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 1 月 6 日
ok
i read your first request a bit too quickly !
I was about to send the code when I noticed that the way you split the data cannot give the same 60 points for all cases :
1-60 => length = 60
5-65 and al followers => length = 61
so we have to change either the lower or the upper limit (like 5-64 and not 5-65)
Mathieu NOE
Mathieu NOE 2021 年 1 月 6 日
so code should be :
data = readmatrix('data.txt');
buffer_length = 60;
k = 5;
nb_loops = 1+fix((length(data)-buffer_length)/k);
% nb_loops = 62;
data_out = [];
for ci = 1:nb_loops
ind_start = 1+(ci-1)*k;
ind_stop = ind_start+buffer_length-1;
ind = ind_start:1:ind_stop;
data_out(:,ci) = data(ind);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by