定位 and/or 调用内置 MATLAB MEX 文件

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

我正在通读一些 MATLAB 源代码,以便将 MATLAB 的 imhist 转换为 Python。在 imhist 内,进行了以下调用:

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

如注释所示,imhistc 来自 MEX 文件。

我可以打开 运行 imhist 没有问题:

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

但是当我尝试用 edit imhistc 打开 imhistc 时,我得到的提示是

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

当我尝试 运行 imhistc 时,出现以下错误:

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

因此,imhistcimhist 可用,但对我不可用。

如何访问 imhistc?我想答案一般适用于内置 MEX 文件。

如果您希望查看 imhistc 中的代码,那您就不走运了。它是一个私有 mex 文件,但它是 编译的 C 代码。在 R2015a 中,至少有一个 imhistc 的私有文档 M 文件,但其中的单行错误检查不会 运行 除非同名的 mex 文件是丢失的。如果有帮助,帮助(在您的命令 Window 中键入 help private/imhistcedit private/imhistc)指示

COUNTS = IMHISTC(A, N, ISSCALED, TOP) computes the N-bin
histogram for A. ISSCALED is 1 if we shouldn't compute the
256-bin histogram using the values in A as is. TOP gives the
maximum bin location.

编译后的文件位于

[matlabroot '/toolbox/images/images/private/']

您可以尝试查看此文件中的内容,但我认为您不会觉得它很有用:

type([matlabroot '/toolbox/images/images/private/imhistc.' mexext])

函数 imhistc,如错误所示,是一个预编译的 mex 文件,因此您无法直接访问其源代码。 which imhistc 不起作用的原因是 imhistc 位于名为 private 的目录中,该目录与 imhist 位于同一文件夹中。你会注意到,如果你查看 private 文件夹,里面还有一个 imhistc.m 文件,但如果 return 的 mex 版本 imhistc 由于某种原因不可用。

这不会帮助您转换程序,但至少会让您知道您在遵循特定代码路径方面遇到了瓶颈。

这已经晚了,但也许将来有人会发现这很有用。我最近和你做同样的事情 运行 遇到同样的问题。我在 google 代码档案中发现了似乎是 imhistc 的存档版本。您可以在

找到它

https://code.google.com/p/mirone/source/browse/trunk/mex/imhistc.c?r=1874&spec=svn1874

我根据那个 C 代码编写了一个简化版本,并且能够得到相同的数字,所以我认为它可能是仍在使用的。

干杯