Filter löschen
Filter löschen

Compute the sum of perimeter of matrix

5 Ansichten (letzte 30 Tage)
David
David am 4 Mär. 2020
Beantwortet: Jemima Pulipati am 9 Mär. 2020
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 Kommentar
James Tursa
James Tursa am 4 Mär. 2020
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jemima Pulipati
Jemima Pulipati am 9 Mär. 2020
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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by