External Interfaces - The MathWorks - #151

/ 649


catalogue search
P. 151
P. 152
P. 153
P. 154
P. 155
P. 156
P. 157
P. 158
P. 159
P. 160
P. 161
P. 162
P. 163
P. 164
P. 165
P. 166
P. 167
P. 168
P. 169
P. 170
P. 171
P. 172
P. 173
P. 174
P. 175
P. 176
P. 177
P. 178
P. 179
P. 180
P. 181
P. 182
P. 183
P. 184
P. 185
P. 186
P. 187
P. 188
P. 189
P. 190
P. 191
P. 192
P. 193
P. 194
P. 195
P. 196
P. 197
P. 198
P. 199
P. 200


See other catalogues for The MathWorks

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

pageCatalog pdf di En 2012-06-22-01