What should I replace 'mxGetName' with?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
Hi James, thanks for the quick answer.
Unfortunately, I can't drop it out from the code as it is used 3 times in the code.
I was wondering if the error in the console could provide any indication on what to use.
So after replacing 'mxGetName' with 'matGetVariable'
warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast
if((nrhs>=8)&&(!strcmp(matGetVariable(prhs[temp_nrhs]),"things"))){
^
.
.
.
note: expected 'const char *' but argument is of type 'int'
int __cdecl strcmp(const char *_Str1,const char *_Str2);
Maybe the ' expected 'const char *'' might point to something? or will it require mexCallMATLAB with "whos" like you said?
If that's the case could you please provide any link that can assist me?
Thanks again for the help
James Tursa
2017년 11월 1일
편집: James Tursa
2017년 11월 1일
You do not want to replace mxGetName with matGetVariable ... these functions do entirely different things.
If you don't want to change your source code, then one way to essentially disable that test simply is to add this function yourself. E.g., add this into your source code:
char things[] = "things"; /* at the top level, not inside a function */
char *mxGetName(const mxArray *mx)
{
return things;
}
This will force your code to always pass that part of the test, essentially disabling it.
If you for some reason really need to check to see if the variable passed in has the name "things" in the caller's workspace let me know (although I don't see why this would be important).
Joseph
2017년 11월 2일
Ok. I'll give that a try. Thank again for the help
Hi James, sorry to prolong this again.
So I placed the function you wrote (the one from the first edited answer) at the top of the code and run it. Now the warning becomes:
warning: assignment from incompatible pointer type
tx_dims = mxGetDimensions(prhs[temp_nrhs]);
And the other warning is:
warning: incompatible implicit declaration of built-in function 'free'
free(start);
I haven't used mxFree() anywhere
You haven't posted the definitions of "tx_dims" and "start", and how "start" is assigned a value. For "tx_dims", it should be:
const mwSize *tx_dims;
I suspect you are using something other than mwSize, like int, in your current code.
For "start", it would need to be assigned a value from one of the native C/C++ memory allocation functions (malloc, calloc, realloc) in order to use free( ). If "start" were assigned a value from one of the MATLAB API memory allocation functions (mxMalloc, mxCalloc, mxRealloc), then you would need to use mxFree( ). I can't advise you definitely in either of these cases since you haven't posted the relevant code for me to see, so I can't tell for sure what the problem is.
You're right, the code uses 'int', and changing to 'mwSize' leads to:
warning: incompatible implicit declaration of built-in function 'malloc'
Basically, I thought I'll bring the code into the modern era as it is very useful for students and researchers and will save time instead of replicating the whole thing again.
But the issues from the 3 mentions of 'mxGetName' in 'irsimit.c' makes it seem like it's not worth it.
James Tursa
2017년 11월 8일
편집: James Tursa
2017년 11월 8일
mxGetName( ) is not the problem. That issue is solved. You likely need to include the appropriate header for malloc:
#include <stdlib.h>
James Tursa
2017년 11월 9일
And I guess I have been assuming all of this time that the "prhs" in your code is the one from the mexFunction argument list. Is this true?
Do you mean from this line?
mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
James Tursa
2017년 11월 9일
Yes.
Well, I've done the following:
- Added the 'char *mxGetName(const mxArray *mx).....' to the top of 'irsimit.c'
- Changed 'int tx_dims;' and 'int rx_dims;' to 'const mwSize *tx_dims;' and 'const mwSize *rx_dims;'
- 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개)
카테고리
도움말 센터 및 File 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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
