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!