필터 지우기
필터 지우기

Compute the sum of perimeter of matrix

조회 수: 1 (최근 30일)
David
David 2020년 3월 4일
답변: Jemima Pulipati 2020년 3월 9일
My TA ask me to make a function code for this specific homework : computes the sum of the elements of an input matrix A that are on the “perimeter” of A.
This is what I have tried so far
function : sum=(A)
M= 2*(sum(A(1,1:end)) + sum(A(1:end,1)) + sum(A(end,1:end)) + sum(A(1:end,end))
end
please help me explain whether i am wrong or right
  댓글 수: 1
James Tursa
James Tursa 2020년 3월 4일
What is the 2 for? Did you try some examples to see if your code produces what you expect? Does your code count the corner elements twice?

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

답변 (1개)

Jemima Pulipati
Jemima Pulipati 2020년 3월 9일
Similar question has already been answered by the community which could be relevant to you. Please refer to the following link.
There is also a function in MathWorks File Exchange which could help you but the matrix should have each dimension atleast 2

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by