Entry point to C/C ++ or Fortran Mex-File

Source: Internet
Author: User
Http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mexfunction.htmlmexFunction (C and Fortran )-
Entry point to C/C ++ or Fortran Mex-File

C syntax
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[]);

FORTRAN
Syntax
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer*4 nlhs, nrhs
mwPointer plhs(*), prhs(*)

Arguments

Nlhs

Number
Of expected outputMxarray
S


Plhs

Array
Of pointers to the expected outputMxarray
S


Nrhs

Number
Of inputMxarray
S


Prhs

Array of pointers to
InputMxarray
S.
Do not modify anyPrhs
Values in your Mex-file.
Changing the data in these read-onlyMxarray
S can
Produce undesired side effects.

Description

Mexico Function
Is not a routine you call.
Rather,Mexico Function
Is the name of the Gateway
Function in C (subroutine in FORTRAN) which every Mex-file requires.
When you invoke a Mex-function, Matlab software finds and Loads
The corresponding Mex-file of the same name. MATLAB then searches
For a symbol namedMexico Function
Within the Mex-file.
If it finds one, It callthe Mex-function using the address ofMexico Function
Symbol. MATLAB displays
An error message if it cannot find a routine namedMexico Function

Inside
The Mex-file.

When you invoke a Mex-file, Matlab automatically
SeedsNlhs
,Plhs
,Nrhs
,
AndPrhs
With the caller's information. In
Syntax of the MATLAB language, functions have the general form:

[a,b,c,...] = fun(d,e,f,...)

Where
The...
Denotes more items of the same
Format.A, B, c...
Are left-hand side arguments,
AndD, e, f...
Are right-hand side arguments.
The argumentsNlhs
AndNrhs
Contain
The number of left-hand side and right-hand side arguments,
Respectively.Prhs
Is
An arrayMxarray
Pointers whose length isNrhs
.Plhs
Is
An array whose length isNlhs
, Where your function
Must set pointers for the returned left-hand sideMxarray
S.

Examples

See
Following examples inMATLAB Root

/Extern/examples/MEX
.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.