mean of matrix elements

조회 수: 1(최근 30일)
john creighton 2014년 10월 15일
댓글: john creighton 2014년 10월 16일
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 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 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 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 2014년 10월 16일
I want have 'vote' too!
out = accumarray(ceil((1:numel(x))'/10),x(:),[],@mean);
댓글 수: 2표시숨기기 이전 댓글 수: 1
john creighton 2014년 10월 16일
haha. yours works too...so well deserved 'vote' :)

댓글을 달려면 로그인하십시오.

john creighton 2014년 10월 16일
Both answers worked perfectly. Thanks guys. sorry can only accept one answer lol
댓글 수: 1표시숨기기 없음
Sean de Wolski 2014년 10월 16일
You can vote too :)

댓글을 달려면 로그인하십시오.

범주

Find more on Matrix Indexing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by