Академический Документы
Профессиональный Документы
Культура Документы
mexErrMsgTxt
mxCreateDoubleMatrix
mxGetM
mxGetN
mxGetPr
mxIsComplex
mxIsSparse
mxIsChar
In MATLAB, mexample accepts two inputs and returns one output. The
inputs are a 2x2 array denoted as ARRAY_IN and a 2x1 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 VECTOR_OUT. All inputs and outputs to
this function are assumed to be real (not complex). */
#include "mex.h"
I) error checking,
II) allocating memory for return arguments,
III) converting data from MATLAB into a format that
the workFcn function can use, and vice versa.
void workFcn(
double theArray[2][2], /* array with data from ARRAY_IN */
double theVector[], /* vector with data from VECTOR_IN */
double theResult[] /* vector with data for VECTOR_OUT */
)
{
double determinant; /* determinant of theArray */
determinant = theArray[0][0]*theArray[1][1]
-theArray[0][1]*theArray[1][0];
theResult[0] = theVector[0]*determinant;
theResult[1] = theVector[1]*determinant;
}
void mexFunction(
int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[]
)
{
double twoDarray[2][2];/* 2 dimensional C array to pass to workFcn() */
int row,col; /* loop indices */
int m,n; /* temporary array size holders */
c=det([1 2; 3 4]) * [1 2]
*/
}