How do I make an average of points ?

조회 수: 2 (최근 30일)
Ernest Adisi
Ernest Adisi 2018년 8월 22일
편집: jonas 2018년 8월 22일
Hi, say I have an 11*10 matrix and for every point in the 6th row, I want matlab to take an average of the surrounding points and make a new row; ie 1 point has 8 surrounding points then the same for each point in the row, how would this be done please ? Thanks
  댓글 수: 2
jonas
jonas 2018년 8월 22일
Please provide an example with input and desired output
Ernest Adisi
Ernest Adisi 2018년 8월 22일
1 2 3 4 5 6 7 8 9 10
5 2 4 6 7 4 5 6 7 8
1 2 3 4 5 6 7 8 9 10
Eg. 2 on the second row would be (1+2+3+5+2+4+1+2+3)/9
Then 4 would be the same pattern
(2+3+4+2+4+6+2+3+4)/9. Etc
So a new row is formed with every point taken as the average of the immediate surrounding points

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

채택된 답변

jonas
jonas 2018년 8월 22일
편집: jonas 2018년 8월 22일
Based on your simple example:
A=[1 2 3 4 5 6 7 8 9 10;
5 2 4 6 7 4 5 6 7 8;
1 2 3 4 5 6 7 8 9 10]
out = conv2(A,ones(3,3)./9,'same')
This will give you the average of all 9 neighboring values. Second row:
out(2,:)
ans =
Columns 1 through 10
1.4444 2.5556 3.3333 4.5556 5.2222 5.7778 6.3333 7.3333 8.3333 5.8889

추가 답변 (1개)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018년 8월 22일
편집: Yuvaraj Venkataswamy 2018년 8월 22일
Check this,
if true
X = rand(11,10);
k = 6;
MA = movmean(X,[(k-1) 0]);
Y = MA(k:k:end,:);
end

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by