Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Matlab Image Restoration Techniques by matlab Content 4899 views
- Matlab Visualizing Data by matlab Content 858 views
- Matlab: Regression by matlab Content 4100 views
- Mex help by Yohannes Masterous 429 views
- Image processing by Pooya Sagharchiha 431 views
- Basics of Image Processing using MA... by E2MATRIX 109 views

No Downloads

Total views

11,448

On SlideShare

0

From Embeds

0

Number of Embeds

203

Shares

0

Downloads

0

Comments

0

Likes

5

No embeds

No notes for slide

- 1. Integrating C, C++ with MATLAB<br />
- 2. Why integrate C/C++ with MATLAB?<br />Speed:<br />C, C++ code can provide really fast computation compared to MATLAB.<br />Data structure management can be a difficult task in C,C++ but very easy in MATLAB.<br />
- 3. Why integrate C/C++ with MATLAB?<br />Data Structure Management<br />Speed<br />
- 4. Integrating C++ with MATLAB<br />For integration of C/C++ with MATLAB, we make use of MEX files<br />MEX files are pre-compiled files that are called from MATLAB<br />MEX files can be compiled from Matlab.m files<br />MEX files can also be compiled from external C/C++ code.<br />
- 5. MEX files<br />
- 6. Components of a MEX file<br />Every MEX file consists of two parts:<br />A gateway routine that interacts with Matlab procedures. Must be called ‘mexFunction()’. This is the point for the C++ code to enter. <br />Subroutine Section which contains any number of subroutines that are called from the gateway routine. Most portion of our computation will be inside these subroutines.<br />
- 7. Writing MEX files<br />It is always assumed when writing C programs that the program will start execution from the main(). On the contrary, MEX -Files always start execution from a special function called the mexFunction(). This function has return type void and is the "gateway" between the MATLAB function call, and our C code.<br />
- 8. Writing MEX files<br />In order to make a mex-function, you must include the "mex.h" library.<br />#include "math.h" <br />#include "mex.h"<br />
- 9. Writing MEX files<br />There are four input parameters to the mexFunction:<br />nlhs (Type = int)<br />plhs (Type = array of pointers to mxArrays)<br />nrhs (Type = int)<br />prhs (Type = const array of pointers to mxArrays)<br />
- 10. Writing MEX files<br />nlhs represents the number of "left hand side" arguments.<br />plhs is the actual output arguments. An mxArray is MATLAB's structure for holding data and each element in plhs holds an mxArray of data.<br />nrhs holds the number of "right hand side" arguments.<br />prhs holds all of the pointers to the mxArrays of input data<br />
- 11. Writing MEX files<br />mxArrayis the main MATLAB structure used for holding data in MEX-Files is the. This structure can hold real data, complex data, arrays, matrices, sparse-arrays, strings, and a whole host of other MATLAB data-structures.<br />
- 12. Calling Built-In Functions from a MEX-File<br />MATLAB has provided the capability of calling pre-written functions in MATLAB. Built-In functions of MATLAB have a parameter list similar to the mexFunction() itself.<br />
- 13. Calling Built-In Functions from a MEX-File<br />Example:<br />mxArray *result;<br />mxArray *arguments[2];<br />arguments[0] = mxCreateDoubleMatrix(1, 20, mxREAL);<br />arguments[1] = mxCreateDoubleMatrix(1, 10, mxREAL);<br />mexCallMATLAB(1,&result,2,arguments,"conv");<br />
- 14. Compiling a MEX file<br />In the MATLAB command prompt:,<br />Change the current directory to the location of the MEX source file. <br />Type: mexfilename.c into the MATLAB command window.<br />MATLAB may ask you to choose a compiler. Choose the compiler with MATLAB in its directory path. <br />The new function will be called with the same name as our file. <br />
- 15. Using the MEX binary<br />After successful compilation of the MEX source file, MATLAB produces the actual MEX binary that can be called as a normal MATLAB function. To call this function, we must be in the same directory as the binary. <br />
- 16. Using the MEX binary<br />On different systems, the MEX binary goes by different extensions:<br />Windows=.dll<br />MacOSX=.mexmac<br />Solaris=.mexsol<br />Linux=.mexlx<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment