mean of matrix elements

1 次查看(过去 30 天)
hey all. i have a 5760x1 matrix. i need to find the average of the first 10 elements, remove the 10 elements and replave with the averaged number, find the average of the next 10 elements, remove those 10 elements and replace with average and so on.... could anyone give me an insight as to how to do this? much appreciated john

采纳的回答

Sean de Wolski
Sean de Wolski 2014-10-15
B = mean(reshape(x,10,[]))'
Where x is your original column vector and B is the mean of every 10x1 chunk

更多回答(3 个)

Andrew Reibold
Andrew Reibold 2014-10-15
编辑:Andrew Reibold 2014-10-15
myMatrix = rand(5760,1)
for jj = 1:576
moving_avg(jj,1) = mean(myMatrix(jj*10-9:jj*10));
end
Will make a matrix called 'moving_avg' where each point represents the average of each set of 10 points.
Is that what you wanted? It will be 1/10 the size.
  1 个评论
Andrew Reibold
Andrew Reibold 2014-10-15
Its very easy to replace every single point with the average too if thats what you need. (Same size, but every set of 10 numbers are all the same averaged number.)

请先登录,再进行评论。


Andrei Bobrov
Andrei Bobrov 2014-10-16
I want have 'vote' too!
out = accumarray(ceil((1:numel(x))'/10),x(:),[],@mean);
  2 个评论
Sean de Wolski
Sean de Wolski 2014-10-16
b=blkproc(rand(5760,1),[10,1],@mean)
I can't think of a solution shorter than my reshape one in terms of Code Golf?
john creighton
john creighton 2014-10-16
haha. yours works too...so well deserved 'vote' :)

请先登录,再进行评论。


john creighton
john creighton 2014-10-16
Both answers worked perfectly. Thanks guys. sorry can only accept one answer lol

类别

Help CenterFile Exchange 中查找有关 Gravitation, Cosmology & Astrophysics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by