calling 2 custom function of the same name

I'd like to know if there is simple way to calling 2 custom functions of the same name. I have one MEX function, and now I need add the new functionality to it, but I do not want to touch any of the existing MEX function, and the interface to all the other users. I just want to write the same name function, add the new functionality, and than call the existing function. I'd like to know if there is any simple way to do it? Thanks.
Julia

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 17일

0 개 추천

Put the new interface in to directory that appears first on the path. Have the new interface loadlib() the previous instance and call it.

댓글 수: 6

julia
julia 2011년 3월 17일
my mex-file is not in the lib, may I still use loadlibary()?
I am not completely sure. If you were using one of the Unix-like systems (Linux, OS-X) then Yes: on those systems there is no real distinction between libraries and executables. I am, though, not familiar with how Windows handles this kind of thing.
julia
julia 2011년 3월 17일
I am using Linux. I only have .mexglx
How can I loadlibary for it?
It appears that you would use loadlibrary() and then calllib() if you were working from the Matlab level.
At the Linux level, use the system call dlopen() to open the .mexglx file, then use dlsym() to get a pointer to the mex routine entry point, typecast it to the appropriate function type, and call through the pointer. The Linux man page for dlopen gives an example.
julia
julia 2011년 3월 18일
I am working from the Matlab level. Using loadliary(myFunc) in myFunc.m, I got: can not find the head file. I do not have the head file for it. I only have the .mexglx file. How can I load it dynamically? Thanks.
You have to create an appropriate .h file to match it, if you want to use loadlib() . You must already know the calling sequence in order to be able to call it without your addition -- or you must at least be able to reverse-engineer the calling sequence by knowing the standard mechanisms that Matlab uses when calling a mex routine.
You indicate that you do not want to touch the existing mex file, but do you have the source for it? If you do, then you can easily extract the calling sequence from there, and fairly readily build a .h file if you need it.

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

추가 답변 (1개)

julia
julia 2011년 3월 22일

0 개 추천

I soved the problem by using soft link and rename the linked file name that is pointing to the orginal function, and put the linked file in the src/ dir.

카테고리

도움말 센터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!

Translated by