Main Content

Build C MEX Function

This example shows how to build the example C MEX function arrayProduct. Use this example to verify the C build configuration for your system. For information about building C++ MEX functions, see Build C++ MEX Programs.

Verify that you have installed a Supported and Compatible Compilers. For information about installing a compiler, visit the vendor website.

mex -setup C

Copy the source MEX file to a writable folder on your path.

copyfile(fullfile(matlabroot,'extern','examples','mex','arrayProduct.c'),'.','f')

Call the mex command to build the function.

mex arrayProduct.c -R2018a

This command creates the file arrayProduct.ext, where ext is the value returned by the mexext function.

Test the function. The arrayProduct function takes a scalar and multiplies it by a 1xN matrix. Call arrayProduct like a MATLAB® function.

s = 5; 
A = [1.5, 2, 9];
B = arrayProduct(s,A)
B =
    7.5000   10.0000   45.0000 

See Also

|

Related Topics

External Websites