See other catalogues for
The MathWorks
You may also be interested in
Text version of the page
| | | | | | | | | | | | |
| | | |
| | | Examples of C Source MEX-Files | | |
| | | |
| | | and your operating system uses mex. bat on Microsoft® Windows® systems and mex.sh on UNIX®10 systems. In either case, typing: mex filename at the prompt produces a compiled version of your MEX-file. In the above example, scalars are viewed as 1-by-1 matrices. Alternatively, you can use a special API function called mxGetScalar that returns the values of scalars instead of pointers to copies of scalar variables (timestwoalt. c). To see the alternative code (error checking has been omitted for brevity), open thefileinMATLABEditor. This example passes the input scalar x by value into the timestwo_alt subroutine, but passes the output scalar y by reference. | | |
| | | |
| | | Passing Strings AnyMATLABtypecan be passedtoand from MEX-files. Theexample revord.c accepts a string and returns the characters in reverse order. To see the example, open the file in MATLAB Editor. In this example, the API function mxCalloc replaces calloc,the standard C function for dynamic memory allocation. mxCalloc allocates dynamic memory using the MATLAB memory manager and initializes it to zero. You must use mxCalloc in any situation where C would require the use of calloc.The same is true for mxMalloc and mxRealloc;use mxMalloc in any situation where C would require the use of malloc and use mxRealloc where C would require realloc. | | |
| | | |
| | | Note MATLAB automatically frees up memory allocated with the mx allocation routines (mxCalloc, mxMalloc, mxRealloc)uponexiting your MEX-file. If you don't want this to happen, use the API function mexMakeMemoryPersistent. | | |
| | | |
| | | 10. UNIX is a registered trademark of The Open Group in the United States and other countries. | | |
| | | |
| | | 4-13 | | |
| | | |
| | | | | | | | | | | | |