Build C MEX Function - MATLAB & Simulink (original) (raw)

Main Content

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.

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 filearrayProduct._`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

mex | mexext

Topics