필터 지우기
필터 지우기

What should I replace 'mxGetName' with?

조회 수: 4 (최근 30일)
Joseph
Joseph 2017년 11월 1일
댓글: Joseph 2017년 11월 10일
I am working with this code and can't compile it because of the deprecated 'mxGetName'.
the line is:
temp_nrhs=7;
if((nrhs>=8)&&(!strcmp(mxGetName(prhs[temp_nrhs]),"things")))
and simply removing it results in a warning
warning: passing argument 1 of 'strcmp' from incompatible pointer type
I'm not sure what can I replace it with.

채택된 답변

James Tursa
James Tursa 2017년 11월 1일
편집: James Tursa 2017년 11월 1일
Variable name strings used to be a part of the mxArray itself. However, that hasn't been the case for several years now. There is no easy way to recover the name of the passed variable other than to use mexCallMATLAB with "whos" and do an exhaustive search for the variable mxArray address to discover its name in the caller's workspace. So, you can either do that, or just drop that part of the test completely out of your mex code.
EDIT
If you really think you need this functionality, you could use the following function. The difference for this function compared to the original is that this function returns a pointer to dynamically allocated memory, so you might want to mxFree( ) it (or allow MATLAB to garbage collect it).
char *mxGetName(const mxArray *mx)
{
mxArray *lhs[1];
mxArray *cell;
size_t i, n;
char *varname;
varname = (char *) mxMalloc(65);
if( mx ) {
mexCallMATLAB(1,lhs,0,NULL,"who");
n = mxGetNumberOfElements(lhs[0]);
for( i=0; i<n; i++ ) {
cell = mxGetCell(lhs[0], i);
mxGetString(cell, varname, 65);
if( mx == mexGetVariablePtr("caller", varname) ) {
mxDestroyArray(lhs[0]);
return varname;
}
}
mxDestroyArray(lhs[0]);
}
varname[0] = '\0';
return varname;
}
  댓글 수: 11
James Tursa
James Tursa 2017년 11월 9일
Yes.
Joseph
Joseph 2017년 11월 10일
Well, I've done the following:
  1. Added the 'char *mxGetName(const mxArray *mx).....' to the top of 'irsimit.c'
  2. Changed 'int tx_dims;' and 'int rx_dims;' to 'const mwSize *tx_dims;' and 'const mwSize *rx_dims;'
  3. Added '#include <stdlib.h>' to 'calculateIt.c'
And now the only thing that comes up is:
mex irsimit.c calculateIt.c planes.c boxes.c visibility.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
Thanks a lot for the help James, it was beyond helpful :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by