Averaging every element with nearby elements
古いコメントを表示
I want to average each element of an m by n matrix with surrounding w elements, for example, if w = 1, the element would be the mean of the 3x3 submatrix with the element in the middle, i.e, if the matrix is
a = [1:10;2:11;3:12;4:13;5:14;6:15;7:16]
and w = 1, each element would be average of nearby eight elements and itself.
I tried using 3 loops, i = 1:w, 1 = w+1:end-w, i = end-w+1:end, but there must be a quicker way to do this.
3 件のコメント
madhan ravi
2019 年 2 月 13 日
Write your expected output explicitly.
Perturabo
2019 年 2 月 13 日
John D'Errico
2019 年 2 月 13 日
I don't think you were that careful in how you computed your example. Or if you were, then you need to explain far better what you want.
採用された回答
その他の回答 (1 件)
KSSV
2019 年 2 月 13 日
0 投票
Read about knnsearch. With this you can get your desired number of nearest neighbors indices.....with the indices you can get your mean.
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!