Find the average between values in a matrix
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (1)
Image Analyst
il 13 Apr 2014
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 Commenti
Alexander
il 13 Apr 2014
Image Analyst
il 13 Apr 2014
Modificato: Image Analyst
il 13 Apr 2014
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
il 13 Apr 2014
Image Analyst
il 13 Apr 2014
Modificato: Image Analyst
il 13 Apr 2014
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:
Categorie
Scopri di più su Correlation and Convolution in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!