How can I change the default function used by Matlab?

I am using the function of conv2 for filtering purpose and I get the error as below
Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d real'.
I used which function and I noticed that the conv2 has 2 built-in function which is single and double and the default function used by Matlab is the single one
>> which conv2 -all
built-in (C:\Program Files\MATLAB\R2012b\toolbox\matlab\datafun\@single\conv2) % single method
built-in (C:\Program Files\MATLAB\R2012b\toolbox\matlab\datafun\@double\conv2) % double method
How can I redirect Matlab to use the function conv2 at double method?

Answers (2)

dpb
dpb on 20 Aug 2014
Edited: dpb on 20 Aug 2014
The problem is not that it's a double; the problem is that you passed a full 3D array to a 2D-limited function as the error says ...and attributes 'full 3d real'.
Pass a single plane or other 2D slice instead of the full array or use convn if actually doing 3D convolution.
ERRATUM -- inserted the missing not in front of the double...sorry, changes meaning significantly.

5 Comments

Liew commented
I wished that I could do the solution that you suggested but the function conv2 is written inside the function of filter2.m file which the cannot be written.
The 3D array actually comes from a tiff image file. Will it be different if I use another file format?
The array is 3D because each slice is a different color channel. Does your algorithm make sense when applied to color images? Do you want to apply the same filter to all color channels? If so, just loop over the slices and filter them one by one.
I did not go through the codes as I am using Libor Masek's code for iris recognition. I downloaded it, and use it straight away without going through the codes.
I imagine he expects grayscale images as input.
well, it works! thanks for your help!!

Sign in to comment.

Sorry, but you misunderstand what you have seen.
The default function is NOT a single precision one.
Functions in an @single directory will be called whenever single precision input is passed in. Likewiese, double precision input will cause the @double codes to be used.
The choice is made automatically, so you need not worry that the wrong one is being used.

1 Comment

Oh, thanks for the info.
I did actually scan through the internet for the answer but did not found this piece of information about the default function.

Sign in to comment.

Asked:

on 20 Aug 2014

Commented:

on 20 Aug 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!