How to Create Basic MEX-functions in CMEX Files?
3 views (last 30 days)
Show older comments
I want a basic example on how to create a C Mex File in MATLAB.
Accepted Answer
MathWorks Support Team
on 30 Jun 2009
Many people have requested a simple example on how to create a C MEX-file in MATLAB 5.0 and later. In response to this request, the attached C MEX-file, named 'mexample', is provided as an introduction to cmex programming. 'mexample' is a commented program which describes how to use the following MEX-functions:
mexErrMsgTxt
mxCreateDoubleMatrix
mxGetM
mxGetN
mxGetPr
mxIsComplex
mxIsSparse
mxIsChar
In MATLAB, mexample accepts two inputs and returns one output. The inputs are a 2-by-2 array denoted as ARRAY_IN and a 2-by-1 vector denoted as VECTOR_IN. The function calculates the determinant of ARRAY_IN, multiplies each element of VECTOR_IN by the determinant, and returns this as the output, denoted by zVECTOR_OUT. All inputs and outputs to this function are assumed to be real (not complex).
0 Comments
More Answers (0)
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!