필터 지우기
필터 지우기

I need to sum the values around the perimeter of a matrix, is there sum function in matlab

조회 수: 2 (최근 30일)
I assume there is a sum function and attempt the following code:
[x,y] =size(M)
Z = M(x:-1:1, y:-1,1);
  댓글 수: 2
DJ V
DJ V 2016년 11월 8일
make that: [x,y] = size(A); y = sum(A(1,1:1:y))+sum(A(y,1:1:y))+sum(A(2:1:X-1,1))+sum(A(2:1:x-1,y));
DJ V
DJ V 2016년 11월 8일
[x,y] = size(A); y = sum(A(1,1:1:y))+sum(A(y,1:1:y))+sum(A(2:1:x-1,1))+sum(A(2:1:x-1,y));

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

답변 (2개)

Daniel kiracofe
Daniel kiracofe 2016년 11월 11일
For your second sum, instead of sum(A(y,1:1:y)) think you wanted sum(A(x,1:1:y))
  댓글 수: 1
Vivek Kumar Chouhan
Vivek Kumar Chouhan 2018년 4월 20일
this code works good for calculating perimeter of matrix of order higher than 2*2 but doesn't work for 2*2 matrix

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


Ibrahim Abouemira
Ibrahim Abouemira 2019년 5월 19일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by