I have a problem about below question. Cab anybody help me??

2 ビュー (過去 30 日間)
SULE SAHIN
SULE SAHIN 2017 年 10 月 27 日
コメント済み: Walter Roberson 2018 年 4 月 27 日
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 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 27 日
Please do not close questions that have an answer.

サインインしてコメントする。

採用された回答

Roger Stafford
Roger Stafford 2017 年 10 月 27 日
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?
  2 件のコメント
SULE SAHIN
SULE SAHIN 2017 年 10 月 27 日
Thank you your hint. function x = peri_sum(A) y = A(1,:) + A(end,:) + A(:,1) + A(:,end); c = sum(y); x = c- (A(1,1) + A(1,end) + A(end,1) + A(end,end)); I thougt this type but this is wrong too.
SULE SAHIN
SULE SAHIN 2017 年 10 月 27 日
My correct answer is; function x = peri_sum(A) x = sum(A(1,:)) + sum(A(end,:)) + sum(A(:,1)) + sum(A(:,end)) - ( A(1,1) + A(1,end) + A(end,1) + A(end,end))
Thank you for your helps

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by