I have a problem about below question. Cab anybody help me??
2 views (last 30 days)
Show older comments
SULE SAHIN
on 27 Oct 2017
Commented: Walter Roberson
on 27 Apr 2018
Write a function called peri_sum that computes the sum of the elements of an input matrix A that are on the “perimeter” of A. In other words, it adds together the elements that are in the first and last rows and columns. Note that the smallest dimension of A is at least 2, but you do not need to check this. Hint: do not double count any elements!
My answer is ;
function sumofthelements = peri_sum(A)
sumofthelements = A(1,1) + A(1,end) + A(end,1) + A(end,end);
I know that I calculate corner sum but I didn't calculate perimeter of A matrix
1 Comment
Accepted Answer
Roger Stafford
on 27 Oct 2017
You have only the sum of the four corners of the matrix. Hint: A(1,:) is a vector consisting of the top row elements of A. How can you use it? What about the other parts of the perimeter?
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!