From: Felix Hebeler on
Hi all.
I've been using colfilt for a while with custom functions.
It's pitty one cannot give pass an extra argument to the
function handle used with colfilt, but I learned to work
around it.
However, I am quite often irritated by what the function
should return, as colfilt often bails out when trying to
reshape the columns back to the original matrix form...

For example, if you use mean with colfilt, as in

B = colfilt(A,[3 3],'sliding',@mean)

everything works fine: mean(X) returns a single value for
the column vector X that is formed by im2col within colfilt.

However, when for example one used a custom function 'test'
<code>
function n = test(X)
n=1;
</code>
which also returns a single value, colfilt bails out:
<code>
??? Error using ==> reshape
To RESHAPE the number of elements must not change.

Error in ==> colfilt at 149
b = reshape(feval(fun,x,params{:}), size(a));
</code>

Even less comprehensible to me is this example:
<code>
% create a 4x4 matrix
test = [ 0 0 0 0; 0 1 0 0; 0 0 0 0; 0 0 2 0];

t=colfilt(test,[2 2],'distinct',@mean)

??? Error using ==> col2im at 60
The row size of B must be M*N.

Error in ==> colfilt at 196
b = col2im(feval(fun,x,params{:}),nhood,size(a),'distinct');
</code>

Can anyone help? I'm lost here...
Using R2008a under Windows (XP32/Vista64)
From: Felix Hebeler on
Ok, I remember now, colfilt creates some temporary matrix
for the test array above that looks like this

n =

0 0 0 0 0 1 0 0 0 0
0 2 0 0 0 0
0 0 0 0 1 0 0 0 0 0
2 0 0 0 0 0
0 1 0 0 0 0 0 2 0 0
0 0 0 0 0 0
1 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0

It has size (4,16), as the block size is 2x2 and the total
number of elements is 16, so any function operating on is
must return a vector of 16 elements, one for each column.

Which still leaves be clueless about the second problem
using the 'distinct' option...