Interfacing MATLAB with C code

Interfacing MATLAB® with user-written C code.

Complimentary Services: Post training email support & 1-hr consultation session within 1 month after the course completion!

TechSource Systems Pte Ltd


This one-day course focuses on interfacing MATLAB® with user-written C code. Through hands-on examples and exercises, the course explores generating MEX-files to incorporate external C code in MATLAB applications and calling MATLAB code from C applications.

TechSource Systems Pte Ltd

Who Should

This hands-on course is designed for engineers who wish to interface their Matlab code with user-written C code.

TechSource Systems Pte Ltd


Familiarity with terminology and concepts related to programming in C (especially pointers). Experience with MATLAB is recommended.

TechSource Systems Pte Ltd


Upon the completion of the course, the participants will At the end of this course, attendees will be able to:

  • Write and compile source MEX files
  • Pass data between MATLAB and MEX files
  • Call MATLAB code from C code using the engine interface
  • Identify the proper approach for interfacing MATLAB with C code


TechSource Systems Pte Ltd
TechSource Systems Pte Ltd

TechSource Systems is MathWorks Authorised Reseller and Training Partner

Upcoming Program

  • Please keep me posted on the next schedule
  • Please contact me to arrange customized/ in-house training

Course Outline

MEX-File Overview

Objective: Identify required components of a MEX-file and set up the environment for producing MEX-files.

  • Introduction to MEX-files
  • Applications of MEX-files
  • Components of a MEX-file
  • Setting up MATLAB to compile MEX-files
  • Building and running a MEX-file
TechSource Systems Pte Ltd
TechSource Systems Pte Ltd

MEX-Files with Inputs and Outputs

Objective: Create MEX-files with inputs and outputs for interacting with MATLAB environment.

  • Data flow in MEX-files
  • MATLAB data
  • The mxArray class
  • Working with pointers
  • Working with mxArray API functions
  • Working with strings
  • When to use MEX-files
  • Handling datas

MEX-File Interface Considerations

Objective: Display diagnostic messages and manage memory in MEX-files.

  • Displaying diagnostic messages
  • Memory allocation and deallocation
  • Preventing memory leaks
  • Working with input and output memory
  • Debugging MEX-files
TechSource Systems Pte Ltd
TechSource Systems Pte Ltd

Calling MATLAB from C Code

Objective: Call the MATLAB engine from a C application to evaluate MATLAB expressions and transfer data between the C application and the MATLAB engine.

  • Introduction to the MATLAB engine
  • Data flow in MATLAB engine applications
  • Calling the MATLAB engine
  • Compiling and running MATLAB engine applications