sum the matrix 3x3 and looping

조회 수: 1 (최근 30일)
renuka
renuka 2014년 2월 28일
편집: renuka 2014년 3월 2일
how to calculate the total of overlap region 3x3 of a matrix and include loop function as it continue to calculate row by row and column by column.
  댓글 수: 2
the cyclist
the cyclist 2014년 2월 28일
편집: the cyclist 2014년 2월 28일
This is not even close to detailed enough to help you. For starters, what does "overlap region" mean?
Please remember, we only know what you tell us about your problem.
renuka
renuka 2014년 3월 1일
편집: renuka 2014년 3월 2일
sorry, it suppose to be like this. i have the code to calculate the sum for the matrix, but dun't know how to do the looping part.
t=rand(6,6)
total = 0;
for i=1:3
for j=1:3
total = total + t(i,j)
end
end

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

채택된 답변

Image Analyst
Image Analyst 2014년 3월 1일
That can be done very simply with imfilter() or conv2():
outputArray = conv2(double(inputArray), ones(3), 'same');
Every element (pixel) in the output array (image) will be the sum of input elements (pixels) in the sliding window.
  댓글 수: 7
Image Analyst
Image Analyst 2014년 3월 2일
편집: Image Analyst 2014년 3월 2일
x = [1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]
theSums = conv2(x, ones(3), 'valid')
Result:
theSums =
54 63
90 99
As you can see, you forgot one sum. Please mark the answer as Accepted if we're done here. Thanks.
renuka
renuka 2014년 3월 2일
thank you very much.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by