matlab function call,Call MATLAB function, user-defined function, or MEX function - MATLAB - MathWor...

mexCallMATLAB (C)

Call MATLAB function, user-defined function, or MEX function

C Syntax

#include "mex.h"

int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs,

mxArray *prhs[], const char *functionName);

Description

Note

To write MEX functions using modern C++ features and the MATLAB Data API, see C++ MEX Applications.

Call mexCallMATLAB to invoke internal MATLAB® numeric functions, MATLAB operators, user-defined functions, or other MEX functions.

Both mexCallMATLAB and mexEvalString execute

MATLAB commands. Use mexCallMATLAB for returning results

(left side arguments) back to the MEX function. The mexEvalString function

does not return values to the MEX function.

Input Arguments

nlhs — Number of output arguments

int

Number of expected output mxArrays, specified as an

integer less than or equal to 50.

plhs — MATLAB arrays

mxArray*

Array of pointers to the mxArray output

arguments.

Caution

The plhs argument for

mexCallMATLAB is not the same as the

plhs for mexFunction. Do not

destroy an mxArray returned in

plhs for mexFunction.

nrhs — Number of input arguments

int

Number of input mxArrays, specified as an integer less

than or equal to 50.

prhs — MATLAB arrays

mxArray*

Array of pointers to the mxArray input

arguments.

functionName — MATLAB function name

const char*

Name of the MATLAB built-in function, operator, user-defined function, or MEX

function to call specified as const char*.

If functionName is an operator, place the operator

inside a pair of double quotes, for example,

"+".

Output Arguments

Status — Status

int

The function returns 0 if successful, and a nonzero

value if unsuccessful.

Error Handling

If functionName detects an error, MATLAB terminates the MEX function and returns control to the MATLAB prompt. To trap errors, use the mexCallMATLABWithTrap

function.

Limitations

Avoid using the mexCallMATLAB function in Simulink® S-functions. If you do, do not store the resulting

plhs

mxArray pointers in any S-function block state that persists

after the MEX function finishes. Outputs of mexCallMATLAB

have temporary scope and are automatically destroyed at the end of the MEX

function call.

It is possible to generate an object of type

mxUNKNOWN_CLASS using mexCallMATLAB.

For example, this function returns two variables but only assigns one of them a

value.

function [a,b] = foo(c)

a = 2*c;

If you then call foo using

mexCallMATLAB, the unassigned output variable is now

type mxUNKNOWN_CLASS.

Examples

See these examples in

matlabroot/extern/examples/mex:

See these examples in

matlabroot/extern/examples/refbook:

See these examples in

matlabroot/extern/examples/mx:

Tips

MATLAB allocates dynamic memory to store the arrays in

plhs for mexCallMATLAB. MATLAB automatically deallocates the dynamic memory when you exit the MEX

function. However, if heap space is at a premium, call

mxDestroyArray when you are finished with the arrays in

plhs.

Introduced before R2006a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值