User`s manual

ii Contents
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46
Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48
2
Creating C Language MEX-Files
C MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
The Components of a C MEX-File . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Required Arguments to a MEX-File . . . . . . . . . . . . . . . . . . . . . . 2-5
Examples of C MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
A First Example — Passing a Scalar . . . . . . . . . . . . . . . . . . . . . 2-7
Passing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Passing Two or More Inputs or Outputs . . . . . . . . . . . . . . . . . . 2-13
Passing Structures and Cell Arrays . . . . . . . . . . . . . . . . . . . . . 2-16
Handling Complex Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Handling 8-,16-, and 32-Bit Data . . . . . . . . . . . . . . . . . . . . . . . 2-23
Manipulating Multidimensional Numerical Arrays . . . . . . . . 2-25
Handling Sparse Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Calling Functions from C MEX-Files . . . . . . . . . . . . . . . . . . . . 2-33
Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37
Help Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37
Linking Multiple Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37
Workspace for MEX-File Functions . . . . . . . . . . . . . . . . . . . . . 2-37
Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Using LAPACK and BLAS Functions . . . . . . . . . . . . . . . . . . . . 2-40
Debugging C Language MEX-Files . . . . . . . . . . . . . . . . . . . . . 2-47
Debugging on UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-47
Debugging on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48