Find the average between values in a matrix
이전 댓글 표시
Suppose im given a 1 X n matrix called a and i want to find matrix b which will give the average value of every element of a and its immediate neighbors
for example. a=[0 2 1 1 0].
b=[1 1 1.3 0.667];
Whats a smart way to do this?
채택된 답변
추가 답변 (1개)
Image Analyst
2014년 4월 13일
You can try conv():
b = conv(a, [1,1,1]/3, 'full')
b = conv(a, [1,1,1]/3, 'valid')
b = conv(a, [1,1,1]/3, 'same')
Each of the shapes handles the "edge conditions" differently. It depends on what you want to do.
댓글 수: 4
Alexander
2014년 4월 13일
Image Analyst
2014년 4월 13일
편집: Image Analyst
2014년 4월 13일
No. Who said anything about that? convolution is just a way of sliding an array past another array multiplying the values in the array together and adding them up. Works for any array. There are versions for 2D and up: conv2() and convn().
Alexander
2014년 4월 13일
Image Analyst
2014년 4월 13일
편집: Image Analyst
2014년 4월 13일
Oh my gosh. Convolution is used everywhere! It's the basis of linear systems theory and linear filtering. As just one example, if you have a sharp image and you blur it by the point spread function of the imaging system you will get an image that is the convolution of the image and the point spread function. And the whole basis of the duality of filtering in Fourier (spectral domain) and spatial (or time) domain is built upon convolution. Basically multiplication in the spatial (or time) domain is convolution in the Fourier domain, and multiplication in the spatial (or time) domain is convolution in the Fourier domain. As soon as you have your first course in linear systems, linear filtering, or optics you should get a heavy intensive education in convolution. Here's some background for you:
카테고리
도움말 센터 및 File Exchange에서 Correlation and Convolution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!