Average of each matrix element due to neighboring elements
조회 수: 7 (최근 30일)
이전 댓글 표시
I looked everywhere and was unable to find an answer. My question is as follows:
I have a single array A that is {<1x1000>} and I need to find the average of each element using the surround elements.
ie,
AVERAGE(1,i) = A(1,i-5) + A(1,i-4) + A(1,i-3) + ... A(1,i) + ... A(1,i+5)
Using in this example 5 as the parameter for my averaging of neighbors and taking into consideration A(1,i).
The next question is how to handle the boundary edges? I know what the boundary edges should look like but they are not the same ie, A(1,1) != A(1,end).
What is the best way to handle both of these cases?
Thank you
댓글 수: 0
채택된 답변
John D'Errico
2016년 9월 26일
편집: John D'Errico
2016년 9월 26일
The best way? That is however you choose to define it. Only you know the best way, for you that is.
To solve the problem, I would just use conv. One line of code to compute the average, which will be correct everywhere but at the ends. Then I would patch the ends as desired. Simple and fast. But you need to decide what you will do at/near the ends. Only you know what you will be using this for, and what you accept as a goal.
For example, you MIGHT consider:
1. Make the end point the average of the 5 last elements.
2. Apply some sort of symmetric boundary conditions at the end. So you might replicate some of the data near the ends appropriately, then conv would apply to the entire series.
Lots of things one could think of.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!