entry point to c/c++ or Fortran MEX-file

http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mexfunction.html


mexFunction (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 output mxArray s

plhs

Array of pointers to the expected output mxArray s

nrhs

Number of input mxArray s

prhs

Array of pointers to the input mxArray s. Do not modify any prhs values in your MEX-file. Changing the data in these read-only mxArray s can produce undesired side effects.

Description

mexFunction is not a routine you call. Rather, mexFunction 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 named mexFunction within the MEX-file. If it finds one, it calls the MEX-function using the address of the mexFunction symbol. MATLAB displays an error message if it cannot find a routine named mexFunction inside the MEX-file.

When you invoke a MEX-file, MATLAB automatically seeds nlhs , plhs , nrhs , and prhs with the caller's information. In the 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. The a,b,c... are left-hand side arguments, and the d,e,f... are right-hand side arguments. The arguments nlhs and nrhs contain the number of left-hand side and right-hand side arguments, respectively. prhs is an array of mxArray pointers whose length is nrhs . plhs is an array whose length is nlhs , where your function must set pointers for the returned left-hand side mxArray s.

Examples

See the following examples in matlabroot /extern/examples/mex .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值