Removing sequential lines from an array using mod MATLAB

44 Views Asked by At

I have a dataset in a nx1 vector. I want to take the average of every 10 points (i.e from 1-10, then 11-20 etc). That easy enough to do with the reshape command when n is divisible by 10. I want to remove the "non-10" elements at the end of the array. Please help.

1

There are 1 best solutions below

0
On

To remove the last incomplete chunk:

x = [10; 20; 30; 40; 50; 60; 70; 80]; % example data: size n x 1
m = 3; % chunk size
y = x(1:floor(end/m)*m);

This gives

y =
    10
    20
    30
    40
    50
    60