Matrix Average beside the numbers

조회 수: 1 (최근 30일)
Lucy Hannah
Lucy Hannah 2019년 4월 30일
답변: Andrei Bobrov 2019년 4월 30일
After creating a matrix of order MxM it will then output a new matrix in which each element is calculated from the original matrix by finding the average of each element adjacent (horizontally, vertically and diagonally) to the original element including the element itself. Each matrix element in the output should have 2 decimal places.
For example M=3 then matrix is [1,2,3;6,5,4;7,8,9]
element ?(1,1) = (1 + 2 + 6 + 5)/ 4 = 3.5
?(1,2) = (1 + 2 + 3 + 6 + 5 + 4) /6 = 3.5

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 4월 30일
M =[ 1 2 3
6 5 4
7 8 9];
X = conv2(M,ones(3),'same')./conv2(ones(3),ones(3),'same');

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by