我尝试使用http://yaafe.sourceforge.net/manual/install.html中的yaafe库。一切都安装好了。但是我想使用matlab接口,我尝试使用以下命令mex yaafemex.cpp
编译yaafemex.cpp,但我在Matlab上有这个错误
Building with 'Xcode Clang++'.
Error using mex
/Users/TMAC/Documents/MATLAB/Add-Ons/Collections/Yaafe/yaafemex.cpp:107:22: error: no matching function for call
to 'mxCreateNumericArray_730'
mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:1111:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:782:1: note: candidate function not viable: no known conversion
from 'int [2]' to 'const size_t *' (aka 'const unsigned long *') for 2nd argument
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag);
^
1 error generated.
部分代码(我没有改变yaafe库提供的初始代码)
yaafemex.cpp
/* write data */
int dims[2] = {buf->info().size , buf->availableTokens()};
mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL); //line 107
double* featdataPtr = (double*) mxGetData(featdata);
buf->read(featdataPtr,buf->availableTokens());
buf->consumeTokens(buf->availableTokens());
mxSetField(feat,0,"data",featdata);
matrix.h
/*
* Create a numeric array and initialize all its data elements to 0.
*
* Similar to mxCreateNumericMatrix, in a standalone application,
* out-of-memory will mean a NULL pointer is returned.
*/
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag); //line 782
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_700(int ndim, const int *dims, mxClassID classid, mxComplexity flag);
答案 0 :(得分:1)
int dims[2] = {buf->info().size , buf->availableTokens()};
签名后,mxCreateNumericArray需要const size_t *,这是一种无符号数字类型。您需要显式转换dims或使用适当的类型定义dims。
具体来说,我在yaafe中编辑dims的定义如下:
size_t dims[2] = {static_cast<size_t>(buf->info().size) , static_cast<size_t>(buf->availableTokens())};