if i have a matrix like A= (1 2 3 4;5 6 7 8;9 10 11 12 ; 13 14 15 16) adding three adjacent elements will look like A(i,j)+A(i,(j+1))+A(i,(j+2)) how can i do this for n adjacent elements ?

 採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 6 月 26 日

2 投票

A= [1 2 3 4;5 6 7 8;9 10 11 12 ; 13 14 15 16];
out = conv2(A,[1 1 1],'valid')

3 件のコメント

OLUBUKOLA ogunsola
OLUBUKOLA ogunsola 2016 年 6 月 26 日
@Andrei Bobrov , thanks . works for addition of three adjacent numbers, how do you make this work for n adjacent numbers? thats the real headache
Stephen23
Stephen23 2016 年 6 月 26 日
Pick N to suit:
conv2(A,ones(1,N),'valid')
OLUBUKOLA ogunsola
OLUBUKOLA ogunsola 2016 年 6 月 26 日
Thanks

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by