{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C function in MATLAB

C function in MATLAB - Connexions module m12348 1 Writing C...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Connexions module: m12348 1 Writing C Functions in MATLAB (MEX-Files) * Jason Laska This work is produced by The Connexions Project and licensed under the Creative Commons Attribution License † Abstract This is a basic guide to writing mex les for MATLAB in C. This guide gives a simple background of some the MATLAB mex features so that learning to write mex les can be quick and easy. 1 Introduction The MATLAB M-File is very good for putting together functions or scripts that run many of MATLAB's fast Built-In functions. One nice thing about these les is that they are never compiled and will run on any system that is already running MATLAB. MATLAB achieves this by interpreting each line of the M-File every time it is run. This method of running the code can make processing time very slow for large and complicated functions, especially those with many loops because every line within the loop will be interpreted as a new line, each time through the loop. Good MATLAB code avoids these things by using as many Built- In features and array operations as possible (because these are fast and e cient). Sometimes this is not enough... MATLAB has the capability of running functions written in C. The les which hold the source for these functions are called MEX-Files. The mexFunctions are not intended to be a substitue for MATLAB's Built- In operations however if you need to code many loops and other things that MATLAB is not very good at, this is a good option. This feature also allows system-speci c APIs to be called to extend MATLAB's abilities (see the Serial Port Tutorial for an example of this). This document is arranged in the following manner: • The MEX-Function: Interface to MATLAB • Getting and Creating Data • Calling Built-In Functions from a MEX-File • Compiling • Useful Functions not Mentioned Here These are some of the basic topics that will allow you to create a MEX- le in a short time. There are many other features and abilities that MATLAB has which can be explored in the MATLAB documentation. * Version 1.2: Aug 1, 2004 5:46 pm GMT-5 † http://creativecommons.org/licenses/by/1.0 http://cnx.org/content/m12348/1.2/ Connexions module: m12348 2 2 The MEX-Function: Interface to MATLAB When writing programs in C, it is always assumed that the program will start execution from the main(). MEX -Files are similar in that they always start execution from a special function called the mexFunction....
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern