0
votes

I'll illustrate my problem on an example

I have a 3x100 matrix and I want to slide a 3x3 filter over it. However, I do not want any of the padding that imfilter would use, such as X, symmetric, replicate, etc., which would yield a 3x100 output. I rather want the sliding window to be only applied when there is real data, such that my output would be 1x (100 - 4).

What would be the most elegant (loopless) way to do this in matlab?

1
Are you using the 'conv' option (or any others) with imfilter? And you can't just use C = imfilter(A,B); C = C(2,2:end-1);? For such small sizes, that's likely to be very efficient. - horchler
I think that you mean that your output would be 1 x 98 rather than 1 x 96 - Suever

1 Answers

1
votes

You can use the built-in conv2 function with 'Valid' as the shape parameter which will only provide results when there is a complete overlap between the filter and the data.

filtered = conv2(data, filter, 'valid');