Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using Matlab with C++

Using Matlab with C++

Using Matlab with C++

Hi there.

I'm working on a project in C++. The thing is that all the math part of it I'm doing in Matlab, that I find so much easier on those aspects.

I'm not quite sure how can I incorporate the Matlab code into the C++ program, though. I readed about creating a dll library, but it was really vague information. Can you guide me through the main steps?


RE: Using Matlab with C++

The standard compiler I believe is LCC


RE: Using Matlab with C++

I think the question was calling Matlab functions from a standalone C++ program.  This is the other way around to the common use of C-MEX functions by Matlab.  The mechanism is the Matlab Engine.  I've not used it myself, but have seen several threads in another forum describing it.  Here is a link:


Don't get confused by the term "Matlab Compiler", this is a deployment tool.

Matlab does ship with LCC, but be aware that this is a C compiler and will not build C++ programs.

- Steve

RE: Using Matlab with C++

Great. I'll go through the compiler documentation and see if I get it clear.


RE: Using Matlab with C++

Hey, I have the Matlab Compiler, and there's many options. The one I want is buiding a C++ library.

Apparently I have to use the command MCC, and in its help it says :

MCC MATLAB to C/C++ Compiler (Version 4.0).
MCC [-options] fun [fun2 ...]


B <filename>[:<arg>[,<arg>]] Specify bundle file. <filename> is a text file
    containing Compiler command line options. The Compiler behaves as if the
    "-B <filename>" were replaced by the contents of the bundle file. Newlines
    appearing in these files are allowed and are treated as whitespace.
    The MathWorks provides options files for the following:

        cpplib    Used for building a C++ library

The thing is that it doesn't work that way, or maybe I'm missing something.

Attached is the matlab code I want to convert to C++.


RE: Using Matlab with C++

There is no built in function (in a library) that does FFT for C++, at least I know of none.
You need to write your own C++ code that does FFT. Do it in discrete form. I'd give you the one I wrote for this, but then I'd have to "sue" you. wink
It's best if you learn this by doing it, so to speak.


RE: Using Matlab with C++

I'm still not clear on the original requirement.

a) Convert the Matlab code into equivalent C++ and incorporate that C++ into your program.

b) Retain your Matlab code, but somehow call it from your C++ program.

c) Other.


a) The "Matlab compiler" will not help you here.  You will almost certainly need to either rewrite the math code in C++.  There are some free Matrix class libraries out there.  Or you could write your own.  I wrote my own when I needed to convert someone elses Matlab into C++.  It's educational.

b) As I said, the Matlab Engine is designed for this.  It will consume a Matlab license when it runs though of course.

c) ??

- Steve

RE: Using Matlab with C++

I don't know, I readed that in many places, that you could build a C++ library with the Matlab compiler, using matlab code... but yeah, anyway, I guess I'll do it all in C++. Doing the fft in C++ is not a problem, I have it already, the thing is that I have a lot of data from different tests I did with Matlab and now I'll have to do it all again.

Thanks people!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close