Search code examples
matlabmex

Locating and/or calling a built-in MATLAB MEX file


I'm reading through some MATLAB source code in order to translate MATLAB's imhist to Python. Inside imhist, the following call is made:

y = imhistc(a, n, isScaled, top);  % Call MEX file to do work.

As the comment implies, imhistc comes from a MEX file.

I can open and run imhist without a problem:

EDU>> edit imhist
EDU>> x = [0.1 0.1 0.1; 0.1 0.1 0.1];
EDU>> counts = imhist(x, 64);

But when I try to open imhistc with edit imhistc, I get a prompt that says,

File /home/daniel/imhistc.m does not exist. Do you want to create it?

And when I try to run imhistc, I get the following error:

EDU>> y = imhistc(x, 64, 1, 1);
??? Undefined function or method 'imhistc' for input arguments of type 'double'.

Thus, imhistc is available to imhist, but unavailable to me.

How can I access imhistc? I'm imagining the answer will apply to built-in MEX files in general.


Solution

  • The function imhistc, as the error implies, is a precompiled mex file, so you won't have direct access to its source code. The reason which imhistc doesn't work is that imhistc is in a directory named private located in the same folder with imhist. You'll note that if you look inside the private folder that there is also a imhistc.m file in there, but it is only there to return an error message if the mex version of imhistc is unavailable for some reason.

    That doesn't help you convert the program, but at least it will let you know that you've hit a brick wall regarding following that particular code path.