Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Table of MEX-File Source Code Files

Source code for the MEX examples shown in the following table is in subfolders of matlabroot/extern/examples. Make sure that you have a MATLAB®-supported compiler installed.

To build a code example, first copy the file to a writable folder, such as c:\work, on your path:

copyfile(fullfile(matlabroot,'extern','examples','foldername',...
  'filename'), fullfile('c:','work'));

where filename is the name of the example, for example arrayProduct.c, and foldername is the subfolder name, for example mex.

You can create and compile MEX-files in MATLAB or at your operating system prompt. At either prompt, type:

mex -v filename

Example Name Example Subfolder Description
arrayFillGetPr.carrayFillGetPr.crefbookFill mxArray using mxGetPr
arrayFillSetData.carrayFillSetData.crefbookFill mxArray with non-double values
arrayFillSetPr.carrayFillSetPr.crefbookFill mxArray using mxSetPr to dynamically allocate memory
arrayProduct.carrayProduct.cmexMultiply a scalar times 1xN matrix
arraySize.carraySize.cmexIllustrate memory requirements of large mxArray
convec.cconvec.c
convec.Fconvec.F
refbookPass complex data
dblmat.Fdblmat.F
compute.Fcompute.F
refbookUse of Fortran %VAL
dotProductComplex.cdotProductComplex.crefbookHandle Fortran complex return type for function called from a C MEX-file
doubleelement.cdoubleelement.crefbookUse unsigned 16-bit integers
explore.cexplore.cmexIdentify data type of input variable
findnz.cfindnz.crefbookUse N-dimensional arrays
fulltosparse.cfulltosparse.c
fulltosparse.Ffulltosparse.F, loadsparse.Floadsparse.F
refbookPopulate a sparse matrix
matrixDivide.cmatrixDivide.crefbookCall a LAPACK function
matrixDivideComplex.cmatrixDivideComplex.crefbookCall a LAPACK function with complex numbers
matrixMultiply.cmatrixMultiply.crefbookCall a BLAS function
matsq.Fmatsq.FrefbookPass matrices in Fortran
matsqint8.Fmatsqint8.FrefbookPass non-double matrices in Fortran
mexatexit.cmexatexit.c
mexatexit.cppmexatexit.cpp
mexRegister an exit function to close a data file
mexcallmatlab.cmexcallmatlab.cmex

Call built-in MATLAB disp function

mexcallmatlabwithtrap.cmexcallmatlabwithtrap.cmexHow to capture error information
mexcpp.cppmexcpp.cppmexIllustrate some C++ language features in a MEX-file
mexevalstring.cmexevalstring.cmexUse mexEvalString to assign variables in MATLAB
mexfunction.cmexfunction.cmexHow to use mexfunction
mexget.cmexget.cmexUse mexGet and mexSet to change Color property of a graphics handle
mexgetarray.cmexgetarray.cmexUse mexGetVariable and mexPutVariable to track counters in the MEX-file and in the MATLAB global workspace
mexlock.cmexlock.c
mexlockf.Fmexlockf.F
mexHow to lock and unlock a MEX-file
mxcalcsinglesubscript.cmxcalcsinglesubscript.cmxDemonstrate MATLAB 1-based matrix indexing versus C 0-based indexing
mxcreatecellmatrix.cmxcreatecellmatrix.c
mxcreatecellmatrixf.Fmxcreatecellmatrixf.F
mxCreate 2-D cell array
mxcreatecharmatrixfromstr.cmxcreatecharmatrixfromstr.cmxCreate 2-D string array
mxcreatestructarray.cmxcreatestructarray.cmxCreate MATLAB structure from C structure
mxgeteps.cmxgeteps.c
mxgetepsf.Fmxgetepsf.F
mx

Read MATLAB eps value

mxgetinf.cmxgetinf.cmxRead inf value
mxgetnzmax.cmxgetnzmax.cmxDisplay number of nonzero elements in a sparse matrix and maximum number of nonzero elements it can store
mxisclass.cmxisclass.cmxCheck if array is member of specified class
mxisfinite.cmxisfinite.cmxCheck for NaN and infinite values
mxislogical.cmxislogical.cmxCheck if workspace variable is logical or global
mxmalloc.cmxmalloc.cmxAllocate memory to copy a MATLAB string to a C string
mxsetdimensions.cmxsetdimensions.c
mxsetdimensionsf.Fmxsetdimensionsf.F
mxReshape an array
mxsetnzmax.cmxsetnzmax.cmxReallocate memory for sparse matrix and reset values of pr, pi, ir and nzmax
passstr.Fpassstr.FrefbookPass C character matrix from Fortran to MATLAB
phonebook.cphonebook.crefbookManipulate structures and cell arrays
revord.crevord.c
revord.Frevord.F
refbookCopy MATLAB string data to and from C-style string
sincall.csincall.c
sincall.Fsincall.F, fill.Ffill.F
refbook

Create mxArray and pass to MATLAB sin and plot functions

timestwo.ctimestwo.c
timestwo.Ftimestwo.F
refbookDemonstrate common workflow of MEX-file
utdu_slv.cutdu_slv.crefbookUse LAPACK for symmetric indefinite factorization
xtimesy.cxtimesy.c
xtimesy.Fxtimesy.F
refbookPass multiple parameters
yprime.cyprime.c
yprimef.Fyprimef.F, yprimefg.Fyprimefg.F
mexSolve simple three body orbit problem

Was this topic helpful?