calculation of a mean

Hi, i have a column with 26668626 rows and 1 column which i will load from an excel file. after i loaded the data wanne have avrage av every 10th row to the end.i wish to put to the new colum.
tried with differet code but the result was not right.
Can someone sopported ?
Thanks Shayan

3 Comments

Adam Danz
Adam Danz on 13 Nov 2018
Edited: Adam Danz on 13 Nov 2018
It's not entirely clear what you want to do. Which of these interpretations (if any) describe what you want:
  1. You want to use a "moving window" to average rows 1-to-10, 2-to-11, 3-to-12, etc.
  2. You want to segement rows in groups of 10 by averagine 1-to-10, 11-to-20, 21-to-30, etc.
  3. You want to average every 10th row meaning rows 10, 20, 30, 40, 50, etc. starting with row 10 which will result in one scalar value that is the average of those rows.
If you want option 2, you will have 6 leftover numbers at the end that don't fit into a group of 10. Are those last 6 numbers to be ignored?
ShayanA
ShayanA on 14 Nov 2018
Thanks for you answer and tip. Perhaps i was not to clear with my question but option 2 is what i wanne do.have a avrage of row segment in groups 1 to 10 & 11 to 20 , 21 to 30 and etc
//Shayan
did you see the answer below ? it has exactly what you need

Sign in to comment.

Answers (3)

dpb
dpb on 13 Nov 2018

1 vote

26668626 isn't evenly divisible by 10; what do you want to do with the leftover 6 elements? You also can't add a column of 1/10th the length of the rest of the array onto the existing array.
Ignoring those last six,
mnx=reshape(mean(reshape(x(1:fix(length(x)/10)),10,[]),1,[]);
will return a column vector of means of each 10 successive elements, ignoring the last six.
Can append mean of those last onto the end or augment the original array to next multiple of 10 with NaN and use nanmean() instead on the resulting array of 26668630 elements.
Bruno Luong
Bruno Luong on 14 Nov 2018

1 vote

splitapply(@mean,data,ceil((1:size(data,1))'/10))

1 Comment

ShayanA
ShayanA on 14 Nov 2018
Hi , and thanks for your support.
Tested right now and its work. . preciated
//Shayan

Sign in to comment.

ShayanA
ShayanA on 14 Nov 2018

0 votes

Yes i saw it now. Appreciate you support.
//Shayan

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Asked:

on 13 Nov 2018

Commented:

on 14 Nov 2018

Community Treasure Hunt

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

Start Hunting!