How to pick data with fix moving window ?

5 views (last 30 days)
aa
aa on 6 Jan 2021
Commented: Mathieu NOE on 6 Jan 2021
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.

Answers (1)

Mathieu NOE
Mathieu NOE on 6 Jan 2021
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 Comments
Mathieu NOE
Mathieu NOE on 6 Jan 2021
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

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!