How to convert mexFunction to general c/c++ function
Show older comments
Hi everyone. I am converting mexFunction to general c/c++ function, so that it can be called in another c/c++ function. I think it's the problem dealing with arguments. How can i do it? Thanks in advance.
4 Comments
Adam
on 17 Dec 2015
It should just be a case of giving the function a proper name and stripping out the mxArray and other Matlab-specific stuff down to the C++ data structures into which you presumably copied the Matlab inputs. Then just pass those into your function instead of the mxArrays.
Farik John
on 25 Dec 2015
James Tursa
on 25 Dec 2015
You pass a pointer to the data. Then work with the data through that pointer in your "general" C/C++ code the same way you would in a mex function. What are you planning to do with this 4D array?
Farik John
on 25 Dec 2015
Answers (1)
Jan
on 25 Dec 2015
0 votes
A clean Mex function uses the mexFunction() function to obtain the pointers to the values of the inputs at first. Then a subsection, or better sub-functions process the data. Finally the mexFunction() creates the outputs for Matlab.
Then it is relatively easy to remove the mexFunction() and use the sub-function for calculations from otehr C-code directly.
But maybe the mexFunction() creates the outputs at first and delivers pointers to allocated arrays to the subfunction. Or the mexFunction() mixes its job as a Matlab-C-gateway with calculations. Then a separation of the Mex and C parts is difficult.
1 Comment
Farik John
on 26 Dec 2015
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!